-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsize_transition_test.go
More file actions
40 lines (31 loc) · 1.01 KB
/
size_transition_test.go
File metadata and controls
40 lines (31 loc) · 1.01 KB
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
package graphics
import (
"testing"
"time"
"github.com/sarumaj/edu-space-invaders/src/pkg/config"
"github.com/sarumaj/edu-space-invaders/src/pkg/numeric"
)
func TestTransition(t *testing.T) {
transition := InitialSizeTransition(numeric.Size{Width: 1, Height: 1}, numeric.Position{X: 0, Y: 0})
transition.SetScale(2)
ticker := time.NewTicker(time.Second / 60)
timer := time.NewTimer(config.Config.Control.AnimationDuration)
defer ticker.Stop()
defer timer.Stop()
test:
for {
select {
case <-ticker.C:
transition.Interpolate()
t.Logf("Size: %v, Position: %v", transition.Size(), transition.Position())
case <-timer.C:
break test
}
}
if !numeric.Equal(transition.Size(), numeric.Size{Width: 2, Height: 2, Scale: 2}, 1e-9) {
t.Errorf("Size: got %v, want %v", transition.Size(), numeric.Size{Width: 2, Height: 2})
}
if !numeric.Equal(transition.Position(), numeric.Position{X: -0.5, Y: -0.5}, 1e-9) {
t.Errorf("Position: got %v, want %v", transition.Position(), numeric.Position{X: 0, Y: 0})
}
}