-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
union_test.go
70 lines (62 loc) · 1.23 KB
/
union_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
package linq_test
import (
"reflect"
"testing"
"github.com/makiuchi-d/linq/v2"
)
func TestUnion(t *testing.T) {
fst := linq.FromSlice([]int{2, 3, 4, 5})
snd := linq.FromSlice([]int{0, 2, 4, 6, 8})
e := linq.Union(
fst, snd,
func(a, b int) (bool, error) { return a == b, nil },
func(a int) (int, error) { return a / 3, nil })
r, err := linq.ToSlice(e)
if err != nil {
t.Fatalf("%v", err)
}
exp := []int{2, 3, 4, 5, 0, 6, 8}
if !reflect.DeepEqual(r, exp) {
t.Fatalf("%v, wants %v", r, exp)
}
}
func TestUnionBy(t *testing.T) {
type Planet struct {
Name string
OrderFromSun int
}
fst := []Planet{
{"Marcury", 1},
{"Venus", 2},
{"Earth", 3},
{"Mars", 4},
{"Jupiter", 5},
}
snd := []Planet{
{"Mars", 4},
{"Jupiter", 5},
{"Saturn", 6},
{"Uranus", 7},
{"Neptune", 8},
}
e := linq.UnionBy(
linq.FromSlice(fst), linq.FromSlice(snd),
func(v Planet) (int, error) { return v.OrderFromSun, nil })
r, err := linq.ToSlice(e)
if err != nil {
t.Fatalf("%v", err)
}
exp := []Planet{
{"Marcury", 1},
{"Venus", 2},
{"Earth", 3},
{"Mars", 4},
{"Jupiter", 5},
{"Saturn", 6},
{"Uranus", 7},
{"Neptune", 8},
}
if !reflect.DeepEqual(r, exp) {
t.Fatalf("%v, wants %v", r, exp)
}
}