benjivers/val Public Public: anyone can read this; the crew can change it.

Files d5bfb1d9a8d63f55abff941a2ed8e47fbe709050
28 lines · 1.0 KB · ~303 tok Raw History
1
import { expect, test } from "bun:test";
2
import { award, CREDIT_CAP, lossBonus, roundReward, spend, START_CREDITS } from "./economy.ts";
3
4
test("a round starts on 800 and nothing goes past 9000", () => {
5
  expect(START_CREDITS).toBe(800);
6
  expect(award(8900, 200)).toBe(CREDIT_CAP);
7
  expect(award(100, -500)).toBe(0);
8
});
9
10
test("the loss bonus rises 1900 / 2400 / 2900 and stops", () => {
11
  expect(lossBonus(1)).toBe(1900);
12
  expect(lossBonus(2)).toBe(2400);
13
  expect(lossBonus(3)).toBe(2900);
14
  expect(lossBonus(7)).toBe(2900);
15
});
16
17
test("a losing attack that planted keeps the plant bonus on top", () => {
18
  expect(roundReward(false, 1, false)).toBe(1900);
19
  expect(roundReward(false, 1, true)).toBe(1900 + 300);
20
  expect(roundReward(true, 3, false)).toBe(3000);
21
});
22
23
test("a buy you cannot afford is refused, never a debt", () => {
24
  expect(spend(800, 2900)).toEqual({ ok: false, credits: 800 });
25
  expect(spend(2900, 2900)).toEqual({ ok: true, credits: 0 });
26
  expect(spend(800, -100).ok).toBe(false);
27
  expect(spend(800, Number.NaN).ok).toBe(false);
28
});
↑↓ navigate ↵ open esc close
↑↓ navigate ↵ open esc close

Keyboard shortcuts