forked from darmie/nanovgo-gles
-
Notifications
You must be signed in to change notification settings - Fork 2
/
nanovgo_test.go
73 lines (57 loc) · 1.36 KB
/
nanovgo_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
package nanovgo
import (
"testing"
)
func TestStateInit(t *testing.T) {
c := Context{}
c.Save()
c.Reset()
topState := c.getState()
if topState.alpha != 1.0 {
t.Errorf("initial alpha should be 1.0, but %f", topState.alpha)
}
}
func TestStateSaveRestore(t *testing.T) {
c := Context{}
c.Save()
c.Reset()
topState := c.getState()
topState.alpha = 0.5
c.Save()
nextState := c.getState()
if nextState.alpha != 0.5 {
t.Errorf("initial alpha should be same with parent's one, but %f", nextState.alpha)
}
nextState.alpha = 0.75
c.Restore()
topStateAgain := c.getState()
if topStateAgain.alpha != 0.5 {
t.Errorf("Restore() should set saved alpha, but %f", topStateAgain.alpha)
}
}
func equal(a1, a2 TransformMatrix) bool {
for i := 0; i < 6; i++ {
if a1[i] != a2[i] {
return false
}
}
return true
}
func TestStateSaveRestore2(t *testing.T) {
c := Context{}
c.Save()
c.Reset()
topState := c.getState()
topState.xform = TranslateMatrix(10, 5)
c.Save()
nextState := c.getState()
if !equal(nextState.xform, TranslateMatrix(10, 5)) {
t.Errorf("initial xform should be same with parent's one, but %v", nextState.xform)
}
nextState.xform = ScaleMatrix(20, 30)
c.Restore()
topStateAgain := c.getState()
if !equal(topStateAgain.xform, TranslateMatrix(10, 5)) {
t.Errorf("Restore() should set saved xform, but %v", topStateAgain.xform)
}
}