-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfuncs_transformation_test.go
42 lines (38 loc) · 1.06 KB
/
funcs_transformation_test.go
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
package handy
import (
"fmt"
"github.com/hsldymq/goiter"
"slices"
"testing"
)
func TestTransform(t *testing.T) {
list := NewList(1, 2, 3, 4, 5)
e := Transform(list, func(each int) string {
return fmt.Sprintf("%d", each*2)
})
actual := []string{}
for v := range e.Iter() {
actual = append(actual, v)
}
expect := []string{"2", "4", "6", "8", "10"}
if !slices.Equal(expect, actual) {
t.Fatalf("test Transform, expect: %v, actual: %v", expect, actual)
}
}
func TestTransformExpand(t *testing.T) {
list := NewList([]int{1, 2, 3}, []int{4, 5, 6}, []int{7, 8, 9})
e := TransformExpand(list, func(each []int) Iterable[int] {
return NewEnumerator(goiter.SliceElems(each))
})
actual := []int{}
for v := range e.Iter() {
actual = append(actual, v)
}
expect := []int{1, 2, 3, 4, 5, 6, 7, 8, 9}
if !slices.Equal(expect, actual) {
t.Fatalf("test TransformExpand, expect: %v, actual: %v", expect, actual)
}
for _ = range e.Iter() {
break
}
}