-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclock_test.go
More file actions
61 lines (51 loc) · 1.57 KB
/
Copy pathclock_test.go
File metadata and controls
61 lines (51 loc) · 1.57 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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package dev_sdk
import (
"testing"
"time"
)
func TestBacktestClock_StartsAtSessionFrom(t *testing.T) {
start := time.Date(2025, 5, 5, 0, 0, 0, 0, time.UTC)
c := newBacktestClock(start)
if got := c.Now(); !got.Equal(start) {
t.Fatalf("expected Now() == %s, got %s", start, got)
}
}
func TestBacktestClock_AdvancesForward(t *testing.T) {
start := time.Date(2025, 5, 5, 0, 0, 0, 0, time.UTC)
c := newBacktestClock(start)
step1 := start.Add(time.Minute)
c.Advance(step1)
if got := c.Now(); !got.Equal(step1) {
t.Fatalf("after first Advance: expected %s, got %s", step1, got)
}
step2 := start.Add(15 * time.Minute)
c.Advance(step2)
if got := c.Now(); !got.Equal(step2) {
t.Fatalf("after second Advance: expected %s, got %s", step2, got)
}
}
func TestBacktestClock_DoesNotRewind(t *testing.T) {
start := time.Date(2025, 5, 5, 0, 0, 0, 0, time.UTC)
c := newBacktestClock(start)
forward := start.Add(time.Hour)
c.Advance(forward)
// Try to rewind — should be ignored.
c.Advance(start)
if got := c.Now(); !got.Equal(forward) {
t.Fatalf("clock should not rewind: expected %s, got %s", forward, got)
}
// Equal time — also ignored (no observable change required either way).
c.Advance(forward)
if got := c.Now(); !got.Equal(forward) {
t.Fatalf("clock should not move on equal time: expected %s, got %s", forward, got)
}
}
func TestWallClock_ReturnsNow(t *testing.T) {
c := wallClock{}
before := time.Now()
got := c.Now()
after := time.Now()
if got.Before(before) || got.After(after) {
t.Fatalf("wallClock.Now() = %s outside [%s, %s]", got, before, after)
}
}