-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils_test.go
87 lines (78 loc) · 2.04 KB
/
utils_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
package spotify
import (
"testing"
)
func TestIsLeft(t *testing.T) {
// prepare test cases
tests := []struct {
name string
either Either[int, string]
want bool
}{
{"Left value", Either[int, string]{isLeft: true, left: 10, right: ""}, true},
{"Right value", Either[int, string]{isLeft: false, left: 0, right: "test"}, false},
}
// execute test cases
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.either.IsLeft(); got != tt.want {
t.Errorf("IsLeft() = %v, want %v", got, tt.want)
}
})
}
}
func TestIsRight(t *testing.T) {
tests := []struct {
name string
either Either[int, string]
want bool
}{
{"Left value", Either[int, string]{isLeft: true, left: 10, right: ""}, false},
{"Right value", Either[int, string]{isLeft: false, left: 0, right: "test"}, true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.either.IsRight(); got != tt.want {
t.Errorf("IsRight() = %v, want %v", got, tt.want)
}
})
}
}
func TestLeft(t *testing.T) {
tests := []struct {
name string
either Either[int, string]
want int
ok bool
}{
{"Left value", Either[int, string]{isLeft: true, left: 10, right: ""}, 10, true},
{"Right value", Either[int, string]{isLeft: false, left: 0, right: "test"}, 0, false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, ok := tt.either.Left()
if got != tt.want || ok != tt.ok {
t.Errorf("Left() = %v, %v, want %v, %v", got, ok, tt.want, tt.ok)
}
})
}
}
func TestRight(t *testing.T) {
tests := []struct {
name string
either Either[int, string]
want string
ok bool
}{
{"Left value", Either[int, string]{isLeft: true, left: 10, right: ""}, "", false},
{"Right value", Either[int, string]{isLeft: false, left: 0, right: "test"}, "test", true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
got, ok := tt.either.Right()
if got != tt.want || ok != tt.ok {
t.Errorf("Right() = %v, %v, want %v, %v", got, ok, tt.want, tt.ok)
}
})
}
}