-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgb_util_test.go
109 lines (91 loc) · 2.58 KB
/
rgb_util_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 spectrum
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestRGBToRGBui8(t *testing.T) {
var tests []struct {
name string
args [3]float64
want [3]uint8
}
for _, c := range AllColours {
tests = append(tests, struct {
name string
args [3]float64
want [3]uint8
}{name: c.Name, args: c.RGB, want: c.RGBui8})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r, g, b := RGBToRGBui8(tt.args[0], tt.args[1], tt.args[2])
assert.Equal(t, tt.want[0], r, "RGBToRGBui8(): R = %v, want %v", r, tt.want[0])
assert.Equal(t, tt.want[1], g, "RGBToRGBui8(): G = %v, want %v", g, tt.want[1])
assert.Equal(t, tt.want[2], b, "RGBToRGBui8(): B = %v, want %v", b, tt.want[2])
})
}
}
func TestRGBui8ToRGB(t *testing.T) {
var tests []struct {
name string
args [3]uint8
want [3]float64
}
for _, c := range AllColours {
tests = append(tests, struct {
name string
args [3]uint8
want [3]float64
}{name: c.Name, args: c.RGBui8, want: c.RGB})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r, g, b := RGBui8ToRGB(tt.args[0], tt.args[1], tt.args[2])
assert.InDeltaf(t, tt.want[0], r, 0.00000001, "RGBui8ToRGB(): R = %v, want %v", r, tt.want[0])
assert.InDeltaf(t, tt.want[1], g, 0.00000001, "RGBui8ToRGB(): G = %v, want %v", g, tt.want[1])
assert.InDeltaf(t, tt.want[2], b, 0.00000001, "RGBui8ToRGB(): B = %v, want %v", b, tt.want[2])
})
}
}
func TestRGBToRGBui32(t *testing.T) {
var tests []struct {
name string
args [3]float64
want uint32
}
for _, c := range AllColours {
tests = append(tests, struct {
name string
args [3]float64
want uint32
}{name: c.Name, args: c.RGB, want: c.RGBui32})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
rgb := RGBToRGBui32(tt.args[0], tt.args[1], tt.args[2])
assert.Equal(t, tt.want, rgb, "RGBToRGBui32(): R = %v, want %v", rgb, tt.want)
})
}
}
func TestRGBui32ToRGB(t *testing.T) {
var tests []struct {
name string
args uint32
want [3]float64
}
for _, c := range AllColours {
tests = append(tests, struct {
name string
args uint32
want [3]float64
}{name: c.Name, args: c.RGBui32, want: c.RGB})
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
r, g, b := RGBui32ToRGB(tt.args)
assert.InDeltaf(t, tt.want[0], r, 0.00000001, "RGBui8ToRGB(): R = %v, want %v", r, tt.want[0])
assert.InDeltaf(t, tt.want[1], g, 0.00000001, "RGBui8ToRGB(): G = %v, want %v", g, tt.want[1])
assert.InDeltaf(t, tt.want[2], b, 0.00000001, "RGBui8ToRGB(): B = %v, want %v", b, tt.want[2])
})
}
}