~whereswaldon/gio-x

ref: b0198a1b547035c76d814b60de9aec3fce6353a8 gio-x/component/color_test.go -rw-r--r-- 1.2 KiB
b0198a1bChris Waldon component: document and refactor tooltip types 5 months ago
                                                                                
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
package component_test

import (
	"image/color"
	"strconv"
	"testing"

	materials "gioui.org/x/component"
)

type interpolationTest struct {
	start, end, expected color.NRGBA
	progress             float32
}

func (i interpolationTest) Run(t *testing.T) {
	interp := materials.Interpolate(i.start, i.end, i.progress)
	if interp != i.expected {
		t.Fatalf("expected interpolation with progress %f to be %v, got %v", i.progress, i.expected, interp)
	}
}

func TestInterpolate(t *testing.T) {
	zero := color.NRGBA{}
	fives := color.NRGBA{R: 5, G: 5, B: 5, A: 5}
	tens := color.NRGBA{R: 10, G: 10, B: 10, A: 10}
	blue := color.NRGBA{R: 64, G: 80, B: 180, A: 255}
	black := color.NRGBA{A: 255}
	for i, testCase := range []interpolationTest{
		{
			start:    zero,
			end:      tens,
			expected: zero,
			progress: 0,
		},
		{
			start:    zero,
			end:      tens,
			expected: tens,
			progress: 1,
		},
		{
			start:    zero,
			end:      tens,
			expected: fives,
			progress: .5,
		},
		{
			start:    tens,
			end:      zero,
			expected: fives,
			progress: .5,
		},
		{
			start:    blue,
			end:      black,
			expected: color.NRGBA{R: 32, G: 40, B: 90, A: 255},
			progress: .5,
		},
	} {
		t.Run(strconv.Itoa(i), testCase.Run)
	}
}