-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathcolors_test.go
53 lines (44 loc) · 973 Bytes
/
colors_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
package gfx
import (
"image/color"
"testing"
)
func TestColorWithAlpha(t *testing.T) {
c := ColorWithAlpha(ColorRGBA(255, 0, 0, 255), 128)
if got, want := c.A, uint8(128); got != want {
t.Fatalf("c.A = %d, want %d", got, want)
}
}
func TestColorNRGBA(t *testing.T) {
got := ColorNRGBA(11, 22, 33, 44)
want := color.NRGBA{11, 22, 33, 44}
if got != want {
t.Fatalf("ColorNRGBA(11,22,33,44) = %v, want %v", got, want)
}
}
func TestColorRGBA(t *testing.T) {
got := ColorRGBA(11, 22, 33, 44)
want := color.RGBA{11, 22, 33, 44}
if got != want {
t.Fatalf("ColorRGBA(11,22,33,44) = %v, want %v", got, want)
}
}
func TestLerpColors(t *testing.T) {
for _, tc := range []struct {
t float64
r uint32
}{
{-10, 65535},
{0.0, 65535},
{0.1, 58981},
{0.5, 32767},
{0.9, 6553},
{1.0, 0},
{100, 0},
} {
c := LerpColors(ColorWhite, ColorBlack, tc.t)
if r, _, _, _ := c.RGBA(); r != tc.r {
t.Fatalf("c.R = %d, want %d", r, tc.r)
}
}
}