BlueGit

timfa questward

Files

questward / server / tests / skull.test.js

skull.test.js

jewelerty, skulls
timfa Tim Falken · pushed by timfa · 2 months ago
2b6e44d0 History
skull.test.js 1.0 KiB Download Raw
1import test from "node:test";
2import assert from "node:assert/strict";
3import
4 {
5 skullValue,
6 skullTintColor,
7 decayKillCounter,
8 SKULL_PURE_RED_VALUE,
9 SKULL_DARK_RED_VALUE,
10 SKULL_KILL_BONUS
11 } from "../../shared/combat/skull.js";
12
13test("skull value is bounty plus kill counter", () =>
14{
15 assert.equal(skullValue(100, 400), 500);
16 assert.equal(skullValue(0, 0), 0);
17 assert.equal(SKULL_KILL_BONUS, 500);
18});
19
20test("kill counter decays one point per second", () =>
21{
22 assert.deepEqual(decayKillCounter(10, 3500), { killCounter: 7, consumedMs: 3000 });
23 assert.deepEqual(decayKillCounter(2, 10_000), { killCounter: 0, consumedMs: 2000 });
24});
25
26test("skull tint: invisible, white, red, dark red", () =>
27{
28 assert.equal(skullTintColor(0), null);
29 assert.deepEqual(skullTintColor(1), { r: 1, g: 1, b: 1 });
30 assert.deepEqual(skullTintColor(SKULL_PURE_RED_VALUE), { r: 1, g: 0, b: 0 });
31 const dark = skullTintColor(SKULL_DARK_RED_VALUE);
32 assert.ok(Math.abs(dark.r - 128 / 255) < 1e-9);
33 assert.equal(dark.g, 0);
34 assert.equal(dark.b, 0);
35});