예제 #1
0
func Benchmark_algo_Map(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.Map(list.GetIterator(), func(v interface{}) interface{} {
			return v
		})
	}
}
예제 #2
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)
	}
}