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

		})
	}
}
예제 #2
0
func Test_algo_ForEach(t *testing.T) {
	var list collect.List = &collect.LinkedList{}
	count := 0
	list.Append(1)
	list.Append(2)
	list.Append(3)
	algo.ForEach(list.GetIterator(), func(v interface{}) {
		if v.(int) > 0 && v.(int) < 4 {
			count = count + 1
		}
	})
	if count == 3 {
		t.Log("Success!")
	} else {
		t.Error("Failed to ForEach")
	}
}