-
Notifications
You must be signed in to change notification settings - Fork 0
/
distinct_test.go
74 lines (68 loc) · 1.27 KB
/
distinct_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
63
64
65
66
67
68
69
70
71
72
73
74
package gcf_test
import (
"fmt"
"testing"
"github.com/meian/gcf"
"github.com/stretchr/testify/assert"
)
func TestDistinct(t *testing.T) {
tests := []struct {
name string
itb gcf.Iterable[int]
want []int
}{
{
name: "uniques",
itb: gcf.FromSlice([]int{1, 4, 3, 2, 5}),
want: []int{1, 2, 3, 4, 5},
},
{
name: "duplicates",
itb: gcf.FromSlice([]int{1, 2, 3, 2, 5}),
want: []int{1, 2, 3, 5},
},
{
name: "single",
itb: gcf.FromSlice([]int{1}),
want: []int{1},
},
{
name: "blank",
itb: gcf.FromSlice([]int{}),
want: []int{},
},
{
name: "nil",
itb: nil,
want: []int{},
},
{
name: "Distinct",
itb: gcf.Distinct(gcf.FromSlice([]int{1, 2, 3, 2})),
want: []int{1, 2, 3},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
itb := gcf.Distinct(tt.itb)
s := gcf.ToSlice(itb)
assert.ElementsMatch(t, tt.want, s)
})
}
itb := gcf.FromSlice([]int{1, 2, 3, 2, 4})
itb = gcf.Distinct(itb)
testBeforeAndAfter(t, itb)
testEmpties(t, gcf.Distinct[int])
}
func ExampleDistinct() {
itb := gcf.FromSlice([]int{1, 4, 2, 3, 2, 3, 1, 2})
itb = gcf.Distinct(itb)
for it := itb.Iterator(); it.MoveNext(); {
fmt.Println(it.Current())
}
// Unordered output:
// 1
// 2
// 3
// 4
}