-
Notifications
You must be signed in to change notification settings - Fork 1
/
distinct_test.go
95 lines (76 loc) · 2.07 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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
package flinx
import (
"testing"
"gotest.tools/v3/assert"
)
func TestDistinct(t *testing.T) {
{
tests := []struct {
input []int
output []int
}{
{[]int{1, 2, 2, 3, 1}, []int{1, 2, 3}},
{[]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, []int{1, 2, 3, 4}},
}
for _, test := range tests {
if q := Distinct(FromSlice(test.input)); !ValidateQuery(q, test.output) {
t.Errorf("From(%v).Distinct()=%v expected %v", test.input, ToSlice(q), test.output)
}
}
}
{
input := "sstr"
output := []rune{'s', 't', 'r'}
if q := Distinct(FromString(input)); !ValidateQuery(q, output) {
t.Errorf("From(%v).Distinct()=%v expected %v", input, ToSlice(q), output)
}
}
}
func TestDistinctForOrderedQuery(t *testing.T) {
{
tests := []struct {
input []int
output []int
}{
{[]int{1, 2, 2, 3, 1}, []int{1, 2, 3}},
{[]int{1, 1, 1, 2, 1, 2, 3, 4, 2}, []int{1, 2, 3, 4}},
}
orderByFn := OrderBy(func(i, j int) int {
return i - j
}, func(i int) int { return i })
for _, test := range tests {
if q := Distinct(FromSlice(test.input)); !ValidateQuery(q, test.output) {
t.Errorf("From(%v).Distinct()=%v expected %v", test.input, ToSlice(q), test.output)
}
}
for _, test := range tests {
if q := orderByFn(Distinct(FromSlice(test.input))).Query; !ValidateQuery(q, test.output) {
t.Errorf("From(%v).Distinct()=%v expected %v", test.input, ToSlice(q), test.output)
}
}
}
{
orderByFn := OrderBy(func(i, j rune) int {
return int(i - j)
}, func(i rune) rune { return i })
input := "sstr"
output := []rune{'r', 's', 't'}
str := ToString(orderByFn(Distinct(FromString(input))).Query)
expect := string(output)
assert.Equal(t, expect, str)
}
}
func TestDistinctBy(t *testing.T) {
type user struct {
id int
name string
}
users := []user{{1, "Foo"}, {2, "Bar"}, {3, "Foo"}}
want := []user{{1, "Foo"}, {2, "Bar"}}
distinctByFn := DistinctBy(func(u user) string {
return u.name
})
if q := distinctByFn(FromSlice(users)); !ValidateQuery(q, want) {
t.Errorf("From(%v).DistinctBy()=%v expected %v", users, ToSlice(q), want)
}
}