| 1 | import test from "node:test"; |
| 2 | import assert from "node:assert/strict"; |
| 3 | import { formatQuantity } from "../../shared/items/formatQuantity.js"; |
| 4 | import { ItemId, coinSpriteTierForQuantity, COIN_MAX_STACK } from "../../shared/definitions/items.js"; |
| 5 | import { addCoinsToSlots, emptySlots, countCoinsInSlots } from "../../shared/items/inventory.js"; |
| 6 | |
| 7 | test("formatQuantity uses compact notation", () => |
| 8 | { |
| 9 | assert.equal(formatQuantity(1), "1"); |
| 10 | assert.equal(formatQuantity(500), "500"); |
| 11 | assert.equal(formatQuantity(1000), "1k"); |
| 12 | assert.equal(formatQuantity(1500), "1.5k"); |
| 13 | assert.equal(formatQuantity(2000), "2k"); |
| 14 | assert.equal(formatQuantity(50000), "50k"); |
| 15 | assert.equal(formatQuantity(100000), "100k"); |
| 16 | assert.equal(formatQuantity(1000000), "1M"); |
| 17 | assert.equal(formatQuantity(1500000), "1.5M"); |
| 18 | }); |
| 19 | |
| 20 | test("coin stacks split above max stack size", () => |
| 21 | { |
| 22 | const amount = COIN_MAX_STACK + 1; |
| 23 | const result = addCoinsToSlots(emptySlots(), amount, { growable: false }); |
| 24 | assert.equal(result.ok, true); |
| 25 | assert.equal(countCoinsInSlots(result.slots), amount); |
| 26 | const stacks = result.slots.filter((slot) => slot?.itemId === ItemId.coins); |
| 27 | assert.equal(stacks.length, 2); |
| 28 | assert.equal(stacks[0].quantity, COIN_MAX_STACK); |
| 29 | assert.equal(stacks[1].quantity, 1); |
| 30 | assert.equal(stacks[0].origins?.[0]?.origin?.kind, "minted"); |
| 31 | assert.equal(stacks[1].origins?.[0]?.origin?.kind, "minted"); |
| 32 | }); |
| 33 | |
| 34 | test("coin sprite tier picks the largest denomination not exceeding stack size", () => |
| 35 | { |
| 36 | assert.equal(coinSpriteTierForQuantity(1), 1); |
| 37 | assert.equal(coinSpriteTierForQuantity(500), 500); |
| 38 | assert.equal(coinSpriteTierForQuantity(1500), 1500); |
| 39 | assert.equal(coinSpriteTierForQuantity(999), 500); |
| 40 | assert.equal(coinSpriteTierForQuantity(50_000_000), 50_000_000); |
| 41 | }); |