-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathclock_test.go
More file actions
47 lines (41 loc) · 1.28 KB
/
Copy pathclock_test.go
File metadata and controls
47 lines (41 loc) · 1.28 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
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2026 The Ebitengine Authors
package debugui_test
import (
"testing"
"testing/synctest"
"time"
"github.com/hajimehoshi/ebiten/v2"
"github.com/ebitengine/debugui"
)
func TestLogicalClockTPSChanges(t *testing.T) {
synctest.Test(t, func(t *testing.T) {
var clock debugui.LogicalClock
check := func(tick int64, tps int, want time.Duration) {
t.Helper()
if got := clock.Read(tick, tps); got != want {
t.Errorf("Read(%d, %d) = %v, want %v", tick, tps, got, want)
}
}
check(0, 60, 0)
time.Sleep(10 * time.Second)
// Fixed-TPS time advances with ticks, regardless of elapsed wall time.
check(60, 120, time.Second)
check(120, ebiten.SyncWithFPS, 1500*time.Millisecond)
time.Sleep(100 * time.Millisecond)
check(121, ebiten.SyncWithFPS, 1600*time.Millisecond)
time.Sleep(150 * time.Millisecond)
check(122, 60, 1750*time.Millisecond)
time.Sleep(time.Second)
check(182, 60, 2750*time.Millisecond)
})
}
func TestLogicalClockFractionalTicks(t *testing.T) {
var clock debugui.LogicalClock
clock.Read(0, 60)
for tick := int64(1); tick <= 60; tick++ {
if got, want := clock.Read(tick, 60), time.Duration(tick)*time.Second/60; got != want {
t.Errorf("tick %d: time = %v, want %v", tick, got, want)
}
}
}