-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtimejump_test.go
71 lines (54 loc) · 1.19 KB
/
timejump_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
package timejump
import (
"math/rand"
"testing"
"time"
)
func TestJump(t *testing.T) {
t.Parallel()
Activate()
defer Deactivate()
now := time.Now()
future := now.AddDate(1, 0, 0)
Jump(future)
if Now().Before(future) {
t.Error("time travel is failed")
}
}
func TestStop(t *testing.T) {
t.Parallel()
Activate()
defer Deactivate()
Stop()
stopped := Now()
for i := 0; i < 10; i++ {
if Now() != stopped {
t.Error("time of the world is not stopped")
}
}
}
func TestScale(t *testing.T) {
t.Parallel()
Activate()
defer Deactivate()
start := Now()
Scale(int(time.Second / time.Millisecond))
time.Sleep(1 * time.Millisecond)
if Now().Before(start.Add(time.Second)) {
t.Errorf("time scale doesn't work well: start is %v, now is %v", start, Now())
}
}
func TestMove(t *testing.T) {
t.Parallel()
Activate()
defer Deactivate()
moveZone, moveOffset := "test/zone", rand.Int()
Move(time.FixedZone(moveZone, moveOffset))
zone, offset := Now().Zone()
if zone != moveZone {
t.Errorf("zone move is failed: expected zone is %v, but got %v", moveZone, zone)
}
if offset != moveOffset {
t.Errorf("zone move is failed: expected offset is %v, but got %v", moveOffset, offset)
}
}