-
Notifications
You must be signed in to change notification settings - Fork 0
/
collectibles_test.go
198 lines (163 loc) · 3.51 KB
/
collectibles_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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
package collectibles
import (
"testing"
"github.com/stretchr/testify/assert"
)
// Byte type vars
var byteSlice = []byte{3, 5, 7, 9, 8, 2}
var byteSlice2 = []byte{3, 5, 7, 4, 8, 2}
var byt *Byt
// Int type vars
var intSlice = []int{3, 5, 7, 9, 8, 2}
var intSlice2 = []int{3, 5, 7, 4, 8, 2}
var intSlice3 = []int{0, 1, 2, 3, 4, 5, 6}
var intr *Intr
//Byte test help methods
func square(b byte) byte {
return b * b
}
func byteExist(b byte) bool {
retVal := false
if b != 0 {
return true
}
if b == 0 {
retVal = false
}
return retVal
}
func byteExistXclusive(b byte) bool {
retVal := false
if b != 0 {
retVal = true
}
if b == 0 {
return false
}
return retVal
}
func isEven(b byte) bool {
if rem := b % 2; rem == 0 {
return true
}
return false
}
func isEqual(b, c byte) bool {
if b == c {
return true
}
return false
}
// Int type help methods
func intSquare(b int) int {
return b * b
}
func intExist(b int) bool {
retVal := false
if b != 0 {
return true
}
if b == 0 {
retVal = false
}
return retVal
}
func intExistXclusive(b int) bool {
retVal := false
if b != 0 {
retVal = true
}
if b == 0 {
return false
}
return retVal
}
func intIsEven(b int) bool {
if rem := b % 2; rem == 0 {
return true
}
return false
}
func intIsEqual(b, c int) bool {
if b == c {
return true
}
return false
}
// Byte type help methods
// Index Test for byte type
func TestIndexForByte(t *testing.T) {
expect := 2
assert.Equal(t, expect, byt.Index(byteSlice, 7))
}
// Map Test for byte type
func TestMapForByte(t *testing.T) {
expect := []byte{9, 25, 49, 81, 64, 4}
assert.Equal(t, expect, byt.Map(byteSlice, square))
}
//Include Test for byte type
func TestIncludeForByte(t *testing.T) {
expect := true
assert.Equal(t, expect, byt.Include(byteSlice, byte(5)))
}
//Any test for byte type
func TestAnyForByte(t *testing.T) {
expect := true
assert.Equal(t, expect, byt.Any(byteSlice, byteExist))
}
//All test for byte type
func TestAllForByte(t *testing.T) {
expect := true
assert.Equal(t, expect, byt.All(byteSlice, byteExistXclusive))
}
//Filter test for byte type
func TestFilterForByte(t *testing.T) {
expect := []byte{8, 2}
assert.Equal(t, expect, byt.Filter(byteSlice, isEven))
}
//Compare test for byte type
func TestCompareForByte(t *testing.T) {
expect := false
assert.Equal(t, expect, byt.Compare(byteSlice, byteSlice2, isEqual))
}
// Int Test Methods
// Index Test for int type
func TestIndexForInt(t *testing.T) {
expect := 2
assert.Equal(t, expect, intr.Index(intSlice, 7))
}
// Map Test for int type
func TestMapForInt(t *testing.T) {
expect := []int{9, 25, 49, 81, 64, 4}
assert.Equal(t, expect, intr.Map(intSlice, intSquare))
}
//Include Test for int type
func TestIncludeForInt(t *testing.T) {
expect := true
assert.Equal(t, expect, intr.Include(intSlice, 5))
}
//Any test for int type
func TestAnyForInt(t *testing.T) {
expect := true
assert.Equal(t, expect, intr.Any(intSlice, intExist))
}
//All test for int type
func TestAllForInt(t *testing.T) {
expect := true
assert.Equal(t, expect, intr.All(intSlice, intExistXclusive))
}
//Filter test for int type
func TestFilterForInt(t *testing.T) {
expect := []int{8, 2}
assert.Equal(t, expect, intr.Filter(intSlice, intIsEven))
}
//Compare test for int type
func TestCompareForInt(t *testing.T) {
expect := false
assert.Equal(t, expect, intr.Compare(intSlice, intSlice2, intIsEqual))
}
//IsConsecutive test for int type
func TestIsConsecutiveForInt(t *testing.T){
expect := true
assert.Equal(t, expect, intr.IsConsecutive(intSlice3))
}