-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex_test.go
117 lines (113 loc) · 2.52 KB
/
index_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
package go2linq
import (
"errors"
"iter"
"testing"
"github.com/solsw/generichelper"
"github.com/solsw/iterhelper"
)
func TestIndex_int(t *testing.T) {
type args struct {
source iter.Seq[int]
}
tests := []struct {
name string
args args
want iter.Seq[generichelper.Tuple2[int, int]]
wantErr bool
expectedErr error
}{
{name: "NilSource",
args: args{
source: nil,
},
wantErr: true,
expectedErr: ErrNilSource,
},
{name: "EmptySource",
args: args{
source: Empty[int](),
},
want: Empty[generichelper.Tuple2[int, int]](),
},
{name: "RegularSource",
args: args{
source: iterhelper.VarSeq(1, 2),
},
want: iterhelper.VarSeq(generichelper.NewTuple2(0, 1), generichelper.NewTuple2(1, 2)),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Index(tt.args.source)
if (err != nil) != tt.wantErr {
t.Errorf("Index() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr {
if !errors.Is(err, tt.expectedErr) {
t.Errorf("Index() error = %v, expectedErr %v", err, tt.expectedErr)
}
return
}
equal, _ := SequenceEqual(got, tt.want)
if !equal {
t.Errorf("Index() = %v, want %v", iterhelper.StringDef(got), iterhelper.StringDef(tt.want))
}
})
}
}
func TestIndex_string(t *testing.T) {
type args struct {
source iter.Seq[string]
}
tests := []struct {
name string
args args
want iter.Seq[generichelper.Tuple2[int, string]]
wantErr bool
expectedErr error
}{
{name: "NilSource",
args: args{
source: nil,
},
wantErr: true,
expectedErr: ErrNilSource,
},
{name: "EmptySource",
args: args{
source: Empty[string](),
},
want: Empty[generichelper.Tuple2[int, string]](),
},
{name: "RegularSource",
args: args{
source: iterhelper.VarSeq("one", "two"),
},
want: iterhelper.VarSeq(
generichelper.NewTuple2(0, "one"),
generichelper.NewTuple2(1, "two"),
),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, err := Index(tt.args.source)
if (err != nil) != tt.wantErr {
t.Errorf("Index() error = %v, wantErr %v", err, tt.wantErr)
return
}
if tt.wantErr {
if !errors.Is(err, tt.expectedErr) {
t.Errorf("Index() error = %v, expectedErr %v", err, tt.expectedErr)
}
return
}
equal, _ := SequenceEqual(got, tt.want)
if !equal {
t.Errorf("Index() = %v, want %v", iterhelper.StringDef(got), iterhelper.StringDef(tt.want))
}
})
}
}