-
Notifications
You must be signed in to change notification settings - Fork 5
/
helpers_test.go
90 lines (82 loc) · 2.07 KB
/
helpers_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
package stagehand
import (
"image"
"testing"
"time"
ebiten "github.com/hajimehoshi/ebiten/v2"
"github.com/stretchr/testify/assert"
)
func TestMaxInt(t *testing.T) {
type args struct {
a int
b int
}
tests := []struct {
name string
args args
want int
}{
{"a bigger", args{2, 1}, 2},
{"b bigger", args{1, 2}, 2},
{"equal", args{1, 1}, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := MaxInt(tt.args.a, tt.args.b); got != tt.want {
t.Errorf("MaxInt() = %v, want %v", got, tt.want)
}
})
}
}
func TestPreDraw(t *testing.T) {
from := &MockScene{}
to := &MockScene{}
toImg, fromImg := PreDraw[int](image.Rect(0, 0, 10, 10), from, to)
assert.True(t, from.drawCalled)
assert.True(t, to.drawCalled)
assert.IsType(t, &ebiten.Image{}, fromImg)
assert.IsType(t, &ebiten.Image{}, toImg)
}
func TestDurationToFactor(t *testing.T) {
type args struct {
frequency float64
duration time.Duration
}
tests := []struct {
name string
args args
want float64
}{
{"1s 1hz", args{1, time.Second}, 1},
{"1s 2hz", args{2, time.Second}, .5},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := DurationToFactor(tt.args.frequency, tt.args.duration); got != tt.want {
t.Errorf("DurationToFactor() = %v, want %v", got, tt.want)
}
})
}
}
func TestCalculateProgress(t *testing.T) {
type args struct {
initialTime time.Time
duration time.Duration
}
tests := []struct {
name string
args args
expected func(float64) bool
}{
{"1s - now", args{time.Now(), time.Second}, func(f float64) bool { return f >= 0 && f <= .1 }},
{"1s - 1s ago", args{time.Now().Add(-time.Second), time.Second}, func(f float64) bool { return f >= 1 && f <= 1.1 }},
{"1s - 2s ago", args{time.Now().Add(-2 * time.Second), time.Second}, func(f float64) bool { return f >= 2 && f <= 2.1 }},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := CalculateProgress(tt.args.initialTime, tt.args.duration); !tt.expected(got) {
t.Errorf("CalculateProgress() = %v", got)
}
})
}
}