-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcolor_test.go
68 lines (58 loc) · 1.88 KB
/
color_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
package blink_test
import (
"fmt"
"testing"
"github.com/fgrosse/blink"
"github.com/stretchr/testify/assert"
)
func TestParseColor(t *testing.T) {
var c blink.Color
c = blink.MustParseColor("123,45,67")
assert.Equal(t, blink.Color{R: 123, G: 45, B: 67}, c)
c = blink.MustParseColor("123, 45, \t67")
assert.Equal(t, blink.Color{R: 123, G: 45, B: 67}, c)
c = blink.MustParseColor("#123456")
assert.Equal(t, blink.Color{R: 18, G: 52, B: 86}, c)
c = blink.MustParseColor("#7b2d43")
assert.Equal(t, blink.Color{R: 123, G: 45, B: 67}, c)
}
func TestMultiply(t *testing.T) {
data := []struct {
have blink.Color
m float64
want blink.Color
}{
{blink.Color{R: 124, G: 64, B: 246}, 0.0, blink.Color{R: 0, G: 0, B: 0}},
{blink.Color{R: 124, G: 64, B: 246}, 0.5, blink.Color{R: 62, G: 32, B: 123}},
{blink.Color{R: 1, G: 73, B: 255}, 0.7, blink.Color{R: 1, G: 51, B: 179}},
{blink.Color{R: 124, G: 64, B: 246}, 1.0, blink.Color{R: 124, G: 64, B: 246}},
{blink.Color{R: 1, G: 73, B: 255}, 1.5, blink.Color{R: 2, G: 110, B: 255}},
{blink.Color{R: 1, G: 73, B: 255}, 2.0, blink.Color{R: 2, G: 146, B: 255}},
{blink.Color{R: 1, G: 73, B: 255}, -1, blink.Color{R: 1, G: 73, B: 255}}, // should be ignored
}
for i, d := range data {
assert.Equal(t, d.want, d.have.Multiply(d.m), fmt.Sprintf("%d: %+v * %.1f", i, d.have, d.m))
}
}
func TestAdd(t *testing.T) {
data := []struct{ have, add, want blink.Color }{
{
blink.Color{R: 0, G: 0, B: 0},
blink.Color{R: 0, G: 0, B: 0},
blink.Color{R: 0, G: 0, B: 0},
},
{
blink.Color{R: 10, G: 20, B: 30},
blink.Color{R: 0, G: 0, B: 0},
blink.Color{R: 10, G: 20, B: 30},
},
{
blink.Color{R: 10, G: 40, B: 100},
blink.Color{R: 20, G: 50, B: 200},
blink.Color{R: 30, G: 90, B: 255},
},
}
for i, d := range data {
assert.Equal(t, d.want, d.have.Add(d.add), fmt.Sprintf("%d: %+v + %+v", i, d.have, d.add))
}
}