github.com/m4gshm/gollections@v0.0.13-0.20240331203319-a34a86e58a24/over/test/ap_go_1_22_test.go (about) 1 //go:build goexperiment.rangefunc 2 3 package test 4 5 import ( 6 "strconv" 7 "testing" 8 9 "github.com/m4gshm/gollections/collection/immutable/ordered/set" 10 "github.com/m4gshm/gollections/over" 11 "github.com/m4gshm/gollections/slice" 12 "github.com/m4gshm/gollections/slice/sort" 13 "github.com/stretchr/testify/assert" 14 ) 15 16 func Test_AllFiltered(t *testing.T) { 17 from := set.Of(1, 2, 3, 5, 7, 8, 9, 11) 18 19 s := []int{} 20 21 for e := range over.Filtered(from.All, func(e int) bool { return e%2 == 0 }) { 22 s = append(s, e) 23 } 24 25 assert.Equal(t, slice.Of(2, 8), sort.Asc(s)) 26 } 27 28 func Test_AllConverted(t *testing.T) { 29 from := set.Of(1, 2, 3, 5, 7, 8, 9, 11) 30 s := []string{} 31 32 for e := range over.Converted(from.All, strconv.Itoa) { 33 s = append(s, e) 34 } 35 36 assert.Equal(t, slice.Of("1", "2", "3", "5", "7", "8", "9", "11"), s) 37 } 38 39 func Benchmark_OrderedSet_Filter_Convert_go1_22(b *testing.B) { 40 c := set.Of(values...) 41 42 var s []string 43 44 b.ResetTimer() 45 for i := 0; i < b.N; i++ { 46 for e := range over.Converted(over.Filtered(c.All, func(e int) bool { return e%2 == 0 }), strconv.Itoa) { 47 s = append(s, e) 48 } 49 } 50 b.StopTimer() 51 52 _ = s 53 }