-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathutils_test.go
67 lines (60 loc) · 1.07 KB
/
utils_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
package blurhash
import (
"fmt"
"math"
"testing"
)
func TestSignPow(t *testing.T) {
var testCases = []struct {
in float64
exp float64
out float64
}{
{-2.0, 4, -16.0},
{2.0, 4, 16.0},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%f", tc.in), func(t *testing.T) {
sp := signPow(tc.in, tc.exp)
if sp != tc.out {
t.Fatalf("got %f, wanted %f", sp, tc.out)
}
})
}
}
func TestLinearTosRGB(t *testing.T) {
var testCases = []struct {
in float64
out int
}{
{0.0, 0},
{1.0, 255},
{0.5, 188},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%f", tc.in), func(t *testing.T) {
sp := linearTosRGB(tc.in)
if sp != tc.out {
t.Fatalf("got %d, wanted %d", sp, tc.out)
}
})
}
}
func TestSRGBToLinear(t *testing.T) {
var testCases = []struct {
in int
out float64
}{
{0, 0.0},
{255, 1.0},
{188, 0.5},
}
for _, tc := range testCases {
t.Run(fmt.Sprintf("%d", tc.in), func(t *testing.T) {
sp := sRGBToLinear(tc.in)
if math.Abs(tc.out-sp) > 0.05 {
t.Fatalf("got %f, wanted %f", sp, tc.out)
}
})
}
}