-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathgradient_test.go
58 lines (50 loc) · 1.3 KB
/
gradient_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
// Copyright (c) Liam Stanley <[email protected]>. All rights reserved. Use of
// this source code is governed by the MIT license that can be found in
// the LICENSE file.
package tint
import (
"image/color"
"reflect"
"testing"
"github.com/lucasb-eyer/go-colorful"
)
func mustHex(t *testing.T, hex string) color.Color {
t.Helper()
c, err := colorful.Hex(hex)
if err != nil {
panic(err)
}
return c
}
func TestFromToHex(t *testing.T) {
tests := []struct {
name string
from color.Color
to color.Color
steps int
wantGradient []string
}{
{
name: "simple-3",
from: mustHex(t, "#000000"),
to: mustHex(t, "#ffffff"),
steps: 3,
wantGradient: []string{"#000000", "#4e4e4e", "#a2a2a2"},
},
{
name: "simple-10",
from: mustHex(t, "#000000"),
to: mustHex(t, "#ffffff"),
steps: 10,
wantGradient: []string{"#000000", "#1b1b1b", "#303030", "#474747", "#5e5e5e", "#777777", "#919191", "#ababab", "#c6c6c6", "#e2e2e2"},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotGradient := FromToHex(tt.from, tt.to, tt.steps)
if !reflect.DeepEqual(gotGradient, tt.wantGradient) {
t.Errorf("FromToHex() = %v, want %v", gotGradient, tt.wantGradient)
}
})
}
}