-
Notifications
You must be signed in to change notification settings - Fork 1
/
int-range-matcher_test.go
120 lines (115 loc) · 2.23 KB
/
int-range-matcher_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
118
119
120
package extra
import (
"reflect"
"testing"
"go.uber.org/mock/gomock"
)
func TestIntRangeMatcher(t *testing.T) {
type args struct {
lowerBound int
upperBound int
}
tests := []struct {
name string
args args
want gomock.Matcher
}{
{
name: "constructor",
args: args{lowerBound: 5, upperBound: 15},
want: &intRangeMatcher{
lowerBound: 5,
upperBound: 15,
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := IntRangeMatcher(tt.args.lowerBound, tt.args.upperBound); !reflect.DeepEqual(got, tt.want) {
t.Errorf("IntRangeMatcher() = %v, want %v", got, tt.want)
}
})
}
}
func Test_intRange_String(t *testing.T) {
type fields struct {
lowerBound int
upperBound int
}
tests := []struct {
name string
fields fields
want string
}{
{
name: "display",
fields: fields{lowerBound: 5, upperBound: 15},
want: "it upper than 5 and lower than 15",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
i := &intRangeMatcher{
lowerBound: tt.fields.lowerBound,
upperBound: tt.fields.upperBound,
}
if got := i.String(); got != tt.want {
t.Errorf("intRange.String() = %v, want %v", got, tt.want)
}
})
}
}
func Test_intRange_Matches(t *testing.T) {
type fields struct {
lowerBound int
upperBound int
}
type args struct {
x interface{}
}
tests := []struct {
name string
fields fields
args args
want bool
}{
{
name: "not an int",
args: args{x: "string"},
want: false,
},
{
name: "not an int 2",
args: args{x: true},
want: false,
},
{
name: "should match 0 case",
args: args{x: 0},
want: true,
},
{
name: "should match in range",
args: args{x: 5},
fields: fields{lowerBound: 1, upperBound: 15},
want: true,
},
{
name: "shouldn't match not in range",
args: args{x: 25},
fields: fields{lowerBound: 1, upperBound: 15},
want: false,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
i := &intRangeMatcher{
lowerBound: tt.fields.lowerBound,
upperBound: tt.fields.upperBound,
}
if got := i.Matches(tt.args.x); got != tt.want {
t.Errorf("intRange.Matches() = %v, want %v", got, tt.want)
}
})
}
}