-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
except_test.go
67 lines (59 loc) · 1.27 KB
/
except_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
package linq_test
import (
"reflect"
"testing"
"github.com/makiuchi-d/linq/v2"
)
func TestExcept(t *testing.T) {
e1 := linq.FromSlice([]string{"Mercury", "Venus", "Earth", "Jupiter"})
e2 := linq.FromSlice([]string{"Mercury", "Earth", "Mars", "Jupiter"})
e := linq.Except(e1, e2,
func(a, b string) (bool, error) { return a == b, nil },
func(a string) (int, error) { return len(a), nil })
r, err := linq.ToSlice(e)
if err != nil {
t.Fatalf("%v", err)
}
exp := []string{"Venus"}
if !reflect.DeepEqual(r, exp) {
t.Fatalf("%q, wants %q", r, exp)
}
}
func TestExceptBy(t *testing.T) {
type PlanetType int
const (
Rock PlanetType = iota
Ice
Gas
Liquid
)
type Planet struct {
Name string
Type PlanetType
OrderFromSun int
}
p1 := []Planet{
{"Marcury", Rock, 1},
{"Venus", Rock, 2},
{"Earth", Rock, 3},
{"Jupiter", Gas, 5},
}
p2 := []Planet{
{"Marcury", Rock, 1},
{"Earth", Rock, 3},
{"Mars", Rock, 4},
{"Jupiter", Gas, 5},
}
e := linq.ExceptBy(
linq.FromSlice(p1),
linq.FromSlice(p2),
func(p Planet) (string, error) { return p.Name, nil })
r, err := linq.ToSlice(e)
if err != nil {
t.Fatalf("%v", err)
}
exp := []Planet{{"Venus", Rock, 2}}
if !reflect.DeepEqual(r, exp) {
t.Fatalf("%v, wants %v", r, exp)
}
}