-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab_test.go
51 lines (42 loc) · 985 Bytes
/
lab_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
package color_test
import (
"fmt"
"math/rand"
"testing"
"github.com/shelepuginivan/color"
"github.com/stretchr/testify/assert"
)
func TestLab(t *testing.T) {
assert.Implements(t, (*color.Color)(nil), color.Lab{})
}
func TestLab_String(t *testing.T) {
for range 1000 {
var (
l = rand.Float64() * 100
a = rand.Float64() * 100
b = rand.Float64() * 100
)
var (
expected = fmt.Sprintf("lab(%.4f, %.4f, %.4f)", l, a, b)
actual = color.NewLab(l, a, b).String()
)
assert.Equal(t, expected, actual)
}
}
func TestLab_Lch(t *testing.T) {
cases := []struct {
color *color.Lab
expected *color.Lch
}{
{
&color.Lab{8.991815706465342, 0.5156084030180363, 3.703827688886369},
&color.Lch{8.991815706465342, 3.7396951758251333, 82},
},
}
for _, c := range cases {
actual := c.color.Lch()
assert.InDelta(t, c.expected.L, actual.L, 0.001)
assert.InDelta(t, c.expected.C, actual.C, 0.001)
assert.Equal(t, c.expected.H, actual.H)
}
}