Пример #1
0
func Benchmark_algo_Reduce(b *testing.B) {
	b.StopTimer()
	var list collect.List = &collect.LinkedList{}
	for i := 0; i < 1000; i++ {
		list.Append(i)
	}
	b.StartTimer()
	for i := 0; i < b.N; i++ {
		algo.Reduce(list.GetIterator(), func(v *interface{}, e interface{}) {
			(*v) = (*v).(int) + (e).(int)
		}, 0)
	}
}
Пример #2
0
func Test_algo_Reduce(t *testing.T) {
	var list collect.List = &collect.LinkedList{}
	list.Append(1)
	list.Append(2)
	list.Append(3)
	sum := algo.Reduce(list.GetIterator(), func(v *interface{}, e interface{}) {
		(*v) = (*v).(int) + e.(int)
	}, 0)
	if sum == 6 {
		t.Log("Success!")
	} else {
		t.Error("Failed to reduce")
	}
}
Пример #3
0
func Test_algo_Map(t *testing.T) {
	var list collect.List = &collect.LinkedList{}
	list.Append(1)
	list.Append(2)
	list.Append(3)
	sum := algo.Reduce(algo.Map(list.GetIterator(), func(v interface{}) interface{} {
		return (v).(int) * (v).(int)
	}), func(v *interface{}, e interface{}) {
		(*v) = (*v).(int) + e.(int)
	}, 0)
	if sum == 14 {
		t.Log("success!")
	} else {
		t.Errorf("Failed to Map %d", sum)
	}
}