-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathintersectby_test.go
40 lines (37 loc) · 1.01 KB
/
intersectby_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
package go2linq
import (
"iter"
"testing"
"github.com/solsw/iterhelper"
)
func TestIntersectBy_Planet(t *testing.T) {
type args struct {
first iter.Seq[Planet]
second iter.Seq[Planet]
keySelector func(Planet) Planet
}
tests := []struct {
name string
args args
want iter.Seq[Planet]
}{
// https://learn.microsoft.com/dotnet/csharp/programming-guide/concepts/linq/set-operations#intersect-and-intersectby
{name: "IntersectBy",
args: args{
first: iterhelper.VarSeq(Mercury, Venus, Earth, Mars, Jupiter),
second: iterhelper.VarSeq(Mars, Jupiter, Saturn, Uranus, Neptune),
keySelector: Identity[Planet],
},
want: iterhelper.VarSeq(Mars, Jupiter),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, _ := IntersectBy(tt.args.first, tt.args.second, tt.args.keySelector)
equal, _ := SequenceEqual(got, tt.want)
if !equal {
t.Errorf("IntersectBy() = %v, want %v", iterhelper.StringDef(got), iterhelper.StringDef(tt.want))
}
})
}
}