-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsome_test.go
153 lines (146 loc) · 3.59 KB
/
some_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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
package option
import (
"reflect"
"testing"
)
func TestSome_Empty(t *testing.T) {
type fields struct {
underlyingValue int
}
tests := []struct {
name string
fields fields
want bool
}{
{name: "Some[T] Empty() returns false", fields: struct{ underlyingValue int }{underlyingValue: 2}, want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := optSome[int]{
underlyingValue: tt.fields.underlyingValue,
}
if got := s.Empty(); got != tt.want {
t.Errorf("Empty() = %v, want %v", got, tt.want)
}
})
}
}
func TestSome_Get(t *testing.T) {
type fields struct {
underlyingValue int
}
tests := []struct {
name string
fields fields
want int
}{
{name: "Some[T] Get returns underlying value", fields: struct{ underlyingValue int }{underlyingValue: 2}, want: 2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := optSome[int]{
underlyingValue: tt.fields.underlyingValue,
}
if got := s.Get(); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Get() = %v, want %v", got, tt.want)
}
})
}
}
func TestSome_GetOrElse(t *testing.T) {
type fields struct {
underlyingValue int
}
type args struct {
v int
}
tests := []struct {
name string
fields fields
args args
want int
}{
{name: "Some[T] GetOrElse() returns underlying value", fields: struct{ underlyingValue int }{underlyingValue: 2}, args: struct{ v int }{v: 3}, want: 2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := optSome[int]{
underlyingValue: tt.fields.underlyingValue,
}
if got := s.GetOrElse(tt.args.v); !reflect.DeepEqual(got, tt.want) {
t.Errorf("GetOrElse() = %v, want %v", got, tt.want)
}
})
}
}
func TestSome_NonEmpty(t *testing.T) {
type fields struct {
underlyingValue int
}
tests := []struct {
name string
fields fields
want bool
}{
{name: "Some[T] NonEmpty() returns true", fields: struct{ underlyingValue int }{underlyingValue: 2}, want: true},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := optSome[int]{
underlyingValue: tt.fields.underlyingValue,
}
if got := s.NonEmpty(); got != tt.want {
t.Errorf("NonEmpty() = %v, want %v", got, tt.want)
}
})
}
}
func TestSome_OrElse(t *testing.T) {
type fields struct {
underlyingValue int
}
type args struct {
opt Option[int]
}
tests := []struct {
name string
fields fields
args args
want Option[int]
}{
{name: "Some[T] OrElse() returns original value with another Some", fields: struct{ underlyingValue int }{underlyingValue: 3}, args: args{opt: Some[int](2)}, want: Some[int](3)},
{name: "Some[T] OrElse() returns original value with another None", fields: struct{ underlyingValue int }{underlyingValue: 3}, args: args{opt: None[int]()}, want: Some[int](3)},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := optSome[int]{
underlyingValue: tt.fields.underlyingValue,
}
if got := s.OrElse(tt.args.opt); !reflect.DeepEqual(got, tt.want) {
t.Errorf("OrElse() = %v, want %v", got, tt.want)
}
})
}
}
func TestSome_String(t *testing.T) {
type fields struct {
underlyingValue int
}
tests := []struct {
name string
fields fields
want string
}{
{name: "Some[T] String() returns Some(T)", fields: struct{ underlyingValue int }{underlyingValue: 2}, want: "Some(2)"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
s := optSome[int]{
underlyingValue: tt.fields.underlyingValue,
}
if got := s.String(); got != tt.want {
t.Errorf("String() = %v, want %v", got, tt.want)
}
})
}
}