Harden gameplay timing and map loading
This commit is contained in:
20
tests/round-clock.test.ts
Normal file
20
tests/round-clock.test.ts
Normal file
@@ -0,0 +1,20 @@
|
||||
import { test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { roundClock } from "../shared/round-clock";
|
||||
|
||||
test("round timer accounts for return latency and stops at the server deadline", () => {
|
||||
const clock = roundClock(100000, 1000, 5000);
|
||||
const deadline = new Date(105000).toISOString();
|
||||
assert.equal(clock.remaining(deadline, 5000), 3);
|
||||
assert.equal(clock.remaining(deadline, 7001), 1);
|
||||
assert.equal(clock.remaining(deadline, 8000), 0);
|
||||
assert.equal(clock.remaining(deadline, 9000), 0);
|
||||
});
|
||||
|
||||
test("round timer relies on elapsed time even if the device wall clock changes", (t) => {
|
||||
const clock = roundClock(100000, 1000, 1000);
|
||||
t.mock.method(Date, "now", () => -10000000);
|
||||
assert.equal(clock.remaining(new Date(110000).toISOString(), 5000), 6);
|
||||
t.mock.method(Date, "now", () => 10000000);
|
||||
assert.equal(clock.remaining(new Date(110000).toISOString(), 11000), 0);
|
||||
});
|
||||
Reference in New Issue
Block a user