1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
package collection
import (
"testing"
"time"
)
func Test_Empty(t *testing.T) {
if Any(Empty) {
t.Log("empty should not have any elements")
t.Fail()
}
if CountAll(Empty) != 0 {
t.Log("empty should have counted to zero elements")
t.Fail()
}
alwaysTrue := func(x interface{}) bool {
return true
}
if Count(Empty, alwaysTrue) != 0 {
t.Log("empty should have counted to zero even when discriminating")
t.Fail()
}
}
func BenchmarkEnumerator_Sum(b *testing.B) {
nums := AsEnumerable(getInitializedSequentialArray()...)
b.ResetTimer()
for i := 0; i < b.N; i++ {
for range nums.Enumerate(nil).Select(sleepIdentity) {
// Intentionally Left Blank
}
}
}
func sleepIdentity(num interface{}) interface{} {
time.Sleep(2 * time.Millisecond)
return Identity(num)
}
func getInitializedSequentialArray() []interface{} {
rawNums := make([]interface{}, 1000, 1000)
for i := range rawNums {
rawNums[i] = i + 1
}
return rawNums
}
|