-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreverse_test.go
62 lines (56 loc) · 1.04 KB
/
reverse_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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package gcf_test
import (
"fmt"
"testing"
"github.com/meian/gcf"
"github.com/stretchr/testify/assert"
)
func TestReverse(t *testing.T) {
tests := []struct {
name string
itb gcf.Iterable[int]
want []int
}{
{
name: "3 elements",
itb: gcf.FromSlice([]int{1, 2, 3}),
want: []int{3, 2, 1},
},
{
name: "1 elements",
itb: gcf.FromSlice([]int{1}),
want: []int{1},
},
{
name: "blank",
itb: gcf.FromSlice([]int{}),
want: []int{},
},
{
name: "nil",
want: []int{},
},
{
name: "reverse",
itb: gcf.Reverse(gcf.FromSlice([]int{1, 2, 3})),
want: []int{1, 2, 3},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
itb := gcf.Reverse(tt.itb)
assert.Equal(t, tt.want, gcf.ToSlice(itb))
})
}
itb := gcf.FromSlice([]int{1, 2, 3})
itb = gcf.Reverse(itb)
testBeforeAndAfter(t, itb)
testEmpties(t, gcf.Reverse[int])
}
func ExampleReverse() {
itb := gcf.FromSlice([]int{1, 3, 2, 4})
itb = gcf.Reverse(itb)
fmt.Println(gcf.ToSlice(itb))
// Output:
// [4 2 3 1]
}