当前位置: 首页>>代码示例>>Golang>>正文


Golang sort.Float64sAreSorted函数代码示例

本文整理汇总了Golang中sort.Float64sAreSorted函数的典型用法代码示例。如果您正苦于以下问题:Golang Float64sAreSorted函数的具体用法?Golang Float64sAreSorted怎么用?Golang Float64sAreSorted使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了Float64sAreSorted函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1: TestRunIncomes

func TestRunIncomes(t *testing.T) {
	JsonObj := []byte(`{"Age":22, "Retirement_age":65, "Terminal_age":90, "Effective_tax_rate":0.3, "Returns_tax_rate":0.3, "N": 20000, 
						"Non_Taxable_contribution":17500, "Taxable_contribution": 0, "Non_Taxable_balance":0, "Taxable_balance": 0, 
						"Yearly_social_security_income":0, "Asset_volatility": 0.15, "Expected_rate_of_return": 0.07, "Inflation_rate":0.035}`)
	rc, err := NewRetCalcFromJSON(JsonObj)
	if err != nil {
		t.Error(err)
	}
	runIncomes := rc.RunIncomes()
	sort.Float64s(runIncomes)
	incomePerRun := make([]float64, rc.N, rc.N)
	for i := range incomePerRun {
		incomePerRun[i] = rc.IncomeOnPath(i)
	}
	sort.Float64s(incomePerRun)
	incomesOk := true
	for i := range incomePerRun {
		if incomePerRun[i] != runIncomes[i] {
			incomesOk = false
			fmt.Printf("RunIncomes: %f, IncomeOnPath: %f\n", runIncomes[i], incomePerRun[i])
		}
	}
	if !incomesOk {
		t.Errorf("Incomes do not calculate correctly for RunIncomes()")
	}
	if !sort.Float64sAreSorted(runIncomes) {
		t.Errorf("Incomes from RetCalc.RunIncomes() should be sorted on return")
	}
}
开发者ID:jd1123,项目名称:retirement_calculator-go,代码行数:29,代码来源:rc_test.go

示例2: med

func (res *Results) med() {
	slice := res.copyTook()
	if !sort.Float64sAreSorted(slice) {
		sort.Float64s(slice)
	}

	l := len(slice)
	switch l {
	case 0:
		res.TookMed = float64(0)
	case 1:
		res.TookMed = slice[0]
	case 2:
		res.TookMed = slice[1]
	default:
		if math.Mod(float64(l), 2) == 0 {
			index := int(math.Floor(float64(l)/2) - 1)
			lower := slice[index]
			upper := slice[index+1]
			res.TookMed = (lower + upper) / 2
		} else {
			res.TookMed = slice[l/2]
		}
	}
}
开发者ID:jmervine,项目名称:goperf,代码行数:25,代码来源:results.go

示例3: TestFloat64s

func TestFloat64s(t *testing.T) {
	data := float64s
	Sort(sort.Float64Slice(data[0:]))
	if !sort.Float64sAreSorted(data[0:]) {
		t.Errorf("sorted %v", float64s)
		t.Errorf("   got %v", data)
	}
}
开发者ID:runningwild,项目名称:sorts,代码行数:8,代码来源:insertion_test.go

示例4: min

func (res *Results) min() {
	slice := res.copyTook()

	if !sort.Float64sAreSorted(slice) {
		sort.Float64s(slice)
	}
	res.TookMin = slice[0]
}
开发者ID:jmervine,项目名称:goperf,代码行数:8,代码来源:results.go

示例5: max

func (res *Results) max() {
	slice := res.copyTook()

	if !sort.Float64sAreSorted(slice) {
		sort.Float64s(slice)
	}
	res.TookMax = slice[len(slice)-1]
}
开发者ID:jmervine,项目名称:goperf,代码行数:8,代码来源:results.go

示例6: sortedCopyDif

// sortedCopyDif returns a sorted copy of float64s
// only if the original data isn't sorted.
// Only use this if returned slice won't be manipulated!
func sortedCopyDif(input Float64Data) (copy Float64Data) {
	if sort.Float64sAreSorted(input) {
		return input
	}
	copy = copyslice(input)
	sort.Float64s(copy)
	return
}
开发者ID:josephburnett,项目名称:stats,代码行数:11,代码来源:util.go

示例7: Max

func (sf64 *SliceFloat64) Max() (float64, error) {
	if len(sf64.Elements) == 0 {
		return 0, errors.New("List is empty")
	}
	if !sort.Float64sAreSorted(sf64.Elements) {
		sort.Float64s(sf64.Elements)
	}
	return sf64.Elements[len(sf64.Elements)-1], nil
}
开发者ID:VukDukic,项目名称:gotilla,代码行数:9,代码来源:slicefloat64.go

示例8: TestSort

func TestSort(t *testing.T) {
	r := testData()
	SortBYOB(r, make([]float64, len(r)))
	if !sort.Float64sAreSorted(r) {
		log.Printf("Should have sorted slice.\n")
		log.Printf("Data was %v", r)
		t.FailNow()
	}
}
开发者ID:shawnsmithdev,项目名称:zermelo,代码行数:9,代码来源:zfloat64_test.go

示例9: Median

func (sf64 *SliceFloat64) Median() (float64, error) {
	if len(sf64.Elements) == 0 {
		return 0, errors.New("List is empty")
	}
	if !sort.Float64sAreSorted(sf64.Elements) {
		sort.Float64s(sf64.Elements)
	}
	mid := int64(float64(len(sf64.Elements)) / 2)
	return sf64.Elements[mid], nil
}
开发者ID:VukDukic,项目名称:gotilla,代码行数:10,代码来源:slicefloat64.go

示例10: TestSortRand

func TestSortRand(t *testing.T) {
	test := func(r []float64) bool {
		SortBYOB(r, make([]float64, len(r)))
		return sort.Float64sAreSorted(r)
	}

	if err := quick.Check(test, nil); err != nil {
		t.Error(err)
	}
}
开发者ID:shawnsmithdev,项目名称:zermelo,代码行数:10,代码来源:zfloat64_test.go

示例11: TestExtractXY

// extractXY should return one series with its x values sorted.
func TestExtractXY(t *testing.T) {
	vals, _ := seriesTestDefaultData(5)
	series := extractXY(vals, "X", "Y")
	if len(series) != 1 {
		t.Fatalf("extractXY returned > 1 series")
	}
	s := series[0]
	if !sort.Float64sAreSorted(s.xs) {
		t.Fatalf("extractXY returned incorrectly sorted series")
	}
}
开发者ID:tflovorn,项目名称:scExplorer,代码行数:12,代码来源:series_test.go

示例12: Sort

// Sort sorts the samples in place in s and returns s.
//
// A sorted sample improves the performance of some algorithms.
func (s *Sample) Sort() *Sample {
	if s.Sorted || sort.Float64sAreSorted(s.Xs) {
		// All set
	} else if s.Weights == nil {
		sort.Float64s(s.Xs)
	} else {
		sort.Sort(&sampleSorter{s.Xs, s.Weights})
	}
	s.Sorted = true
	return s
}
开发者ID:rchunping,项目名称:go-gcstats,代码行数:14,代码来源:sample.go

示例13: TestFloat64s

func TestFloat64s(t *testing.T) {
	data := float64s

	for _, alg := range algorithms {
		sorting.Float64s(data[:], alg)
		if !sort.Float64sAreSorted(data[:]) {
			t.Errorf("%v\n", util.GetFuncName(alg))
			t.Errorf("sorted: %v\n", float64s)
			t.Errorf("   got: %v\n", data)
		}
	}
}
开发者ID:tornyak,项目名称:goalg,代码行数:12,代码来源:sort_test.go

示例14: TestAdjustLeftRight

func TestAdjustLeftRight(t *testing.T) {

	keys := []float64{1, 2, 3, 4, 9, 5, 6, 7, 8}
	counts := []uint32{1, 2, 3, 4, 9, 5, 6, 7, 8}

	s := summary{keys: keys, counts: counts}

	s.adjustRight(4)

	if !sort.Float64sAreSorted(s.keys) || s.counts[4] != 5 {
		t.Errorf("adjustRight should have fixed the keys/counts state. %v %v", s.keys, s.counts)
	}

	keys = []float64{1, 2, 3, 4, 0, 5, 6, 7, 8}
	counts = []uint32{1, 2, 3, 4, 0, 5, 6, 7, 8}

	s = summary{keys: keys, counts: counts}
	s.adjustLeft(4)

	if !sort.Float64sAreSorted(s.keys) || s.counts[4] != 4 {
		t.Errorf("adjustLeft should have fixed the keys/counts state. %v %v", s.keys, s.counts)
	}
}
开发者ID:caio,项目名称:go-tdigest,代码行数:23,代码来源:summary_test.go

示例15: Median

func Median(list []float64) (float64, error) {
	if len(list) == 0 {
		return 0.0, errors.New("Empty list given")
	}

	if !sort.Float64sAreSorted(list) {
		sort.Float64s(list)
	}

	if len(list)%2 == 1 {
		return list[(len(list) / 2)], nil
	}

	return (list[len(list)/2] + list[len(list)/2-1]) / 2, nil
}
开发者ID:SiroDiaz,项目名称:go-statistics,代码行数:15,代码来源:median.go


注:本文中的sort.Float64sAreSorted函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。