-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
main_test.go
109 lines (85 loc) Β· 2.28 KB
/
main_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
package main
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestStringToUint32Success(t *testing.T) {
expected := []uint32{
1320097209,
728769438,
3408452011,
2797316833,
}
actual := []uint32{
stringToUint32("username"),
stringToUint32("mitch"),
stringToUint32("hello_world!"),
stringToUint32("196b0f14eba66e10fba74dbf9e99c22f"),
}
for i := 0; i < len(expected); i++ {
assert.Equal(t, expected[i], actual[i])
}
}
func TestStringToUint32CorrectFailure(t *testing.T) {
expected := []uint32{
1320097209,
728769438,
3408452011,
2797316833,
}
actual := []uint32{
stringToUint32("_"),
stringToUint32("linux"),
stringToUint32("goodbye_world?"),
stringToUint32("7815696ecbf1c96e6894b779456d330e"),
}
for i := 0; i < len(expected); i++ {
assert.NotEqual(t, expected[i], actual[i])
}
}
func TestGenerateRGBFromStringSuccess(t *testing.T) {
expected := []RGBColor{
RGBColor{38, 130, 40},
RGBColor{130, 82, 6},
RGBColor{33, 136, 98},
}
actual := []RGBColor{
generateRGBFromString("fae53351b9effc708e764e871bef3119", 2),
generateRGBFromString("fae53351b9effc708e764e871bef3119", 4),
generateRGBFromString("4e3ef92ed95e0776ff69797b475ccd58", 1),
}
for i := 0; i < len(expected); i++ {
expectedRed := expected[i].R
actualRed := actual[i].R
expectedGreen := expected[i].G
actualGreen := actual[i].G
expectedBlue := expected[i].B
actualBlue := actual[i].B
assert.Equal(t, expectedRed, actualRed)
assert.Equal(t, expectedGreen, actualGreen)
assert.Equal(t, expectedBlue, actualBlue)
}
}
func TestGenerateRGBFromStringFailure(t *testing.T) {
expected := []RGBColor{
RGBColor{32, 130, 40},
RGBColor{120, 82, 6},
RGBColor{33, 131, 98},
}
actual := []RGBColor{
generateRGBFromString("fae5d351b9effc708e764e871bef3119", 5),
generateRGBFromString("fae533a1b9effc708e764e871bef3119", 3),
generateRGBFromString("4e3ef9aed95e0776ff69797b475ccd58", 2),
}
for i := 0; i < len(expected); i++ {
expectedRed := expected[i].R
actualRed := actual[i].R
expectedGreen := expected[i].G
actualGreen := actual[i].G
expectedBlue := expected[i].B
actualBlue := actual[i].B
assert.NotEqual(t, expectedRed, actualRed)
assert.NotEqual(t, expectedGreen, actualGreen)
assert.NotEqual(t, expectedBlue, actualBlue)
}
}