-
-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathsharp_test.go
91 lines (69 loc) · 2.43 KB
/
sharp_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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package colorgrad
import (
"math"
"testing"
)
func Test_SharpGradient(t *testing.T) {
var grad, gradBase Gradient
gradBase, _ = NewGradient().
HtmlColors("#f00", "#0f0", "#00f").
Build()
// Sharp(0)
grad = gradBase.Sharp(0, 0)
test(t, grad.At(0.0).HexString(), "#ff0000")
test(t, grad.At(0.5).HexString(), "#ff0000")
test(t, grad.At(1.0).HexString(), "#ff0000")
// Sharp(1)
grad = gradBase.Sharp(1, 0)
test(t, grad.At(0.0).HexString(), "#ff0000")
test(t, grad.At(0.5).HexString(), "#ff0000")
test(t, grad.At(1.0).HexString(), "#ff0000")
// Sharp(3)
grad = gradBase.Sharp(3, 0)
test(t, grad.At(0.0).HexString(), "#ff0000")
test(t, grad.At(0.2).HexString(), "#ff0000")
test(t, grad.At(0.4).HexString(), "#00ff00")
test(t, grad.At(0.5).HexString(), "#00ff00")
test(t, grad.At(0.6).HexString(), "#00ff00")
test(t, grad.At(0.9).HexString(), "#0000ff")
test(t, grad.At(1.0).HexString(), "#0000ff")
test(t, grad.At(-0.1).HexString(), "#ff0000")
test(t, grad.At(1.1).HexString(), "#0000ff")
test(t, grad.At(math.NaN()).HexString(), "#000000")
// Sharp(2)
gradBase, _ = NewGradient().
HtmlColors("#f00", "#0f0", "#00f").
Domain(-1, 1).
Build()
grad = gradBase.Sharp(2, 0)
test(t, grad.At(-1.0).HexString(), "#ff0000")
test(t, grad.At(-0.5).HexString(), "#ff0000")
test(t, grad.At(-0.1).HexString(), "#ff0000")
test(t, grad.At(0.1).HexString(), "#0000ff")
test(t, grad.At(0.5).HexString(), "#0000ff")
test(t, grad.At(1.0).HexString(), "#0000ff")
// Smoothness
gradBase, _ = NewGradient().
HtmlColors("#f00", "#0f0", "#00f").
Build()
grad = gradBase.Sharp(0, 0.5)
test(t, grad.At(0.0).HexString(), "#ff0000")
test(t, grad.At(0.5).HexString(), "#ff0000")
test(t, grad.At(1.0).HexString(), "#ff0000")
grad = gradBase.Sharp(1, 0.5)
test(t, grad.At(0.0).HexString(), "#ff0000")
test(t, grad.At(0.5).HexString(), "#ff0000")
test(t, grad.At(1.0).HexString(), "#ff0000")
grad = gradBase.Sharp(3, 0.1)
test(t, grad.At(0).HexString(), "#ff0000")
test(t, grad.At(0.1).HexString(), "#ff0000")
test(t, grad.At(1.0/3).HexString(), "#808000")
test(t, grad.At(0.45).HexString(), "#00ff00")
test(t, grad.At(0.55).HexString(), "#00ff00")
test(t, grad.At(1.0/3*2).HexString(), "#008080")
test(t, grad.At(0.9).HexString(), "#0000ff")
test(t, grad.At(1).HexString(), "#0000ff")
test(t, grad.At(-0.01).HexString(), "#ff0000")
test(t, grad.At(1.01).HexString(), "#0000ff")
test(t, grad.At(math.NaN()).HexString(), "#000000")
}