summaryrefslogtreecommitdiff
path: root/web/test/levelValues.test.ts
blob: bdcb08c24a9644a342e5a8d0fe9108cd017d67c4 (plain)
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import { describe, it, expect } from 'vitest';
import {
	coinValue,
	hazardValue,
	recommendedLevel,
	trapValue,
	xpValue
} from '$lib/game/levelValues';

describe('level values (GameMethods port)', () => {
	it('trap = 2 + level', () => {
		expect(trapValue(1)).toBe(3);
		expect(trapValue(10)).toBe(12);
	});

	it('hazard = 1 + ceil(level / 3)', () => {
		expect(hazardValue(1, false, false)).toBe(2);
		expect(hazardValue(3, false, false)).toBe(2);
		expect(hazardValue(4, false, false)).toBe(3);
	});

	it('OGGloom hazard halves the trap value by default', () => {
		// floor((2 + level) / 2)
		expect(hazardValue(1, true, false)).toBe(1);
		expect(hazardValue(5, true, false)).toBe(3);
	});

	it('OGGloom with the FH setting uses the regular formula', () => {
		expect(hazardValue(5, true, true)).toBe(3); // 1 + ceil(5/3)
		expect(hazardValue(4, true, true)).toBe(3); // 1 + ceil(4/3)
	});

	it('xp = 4 + 2 * level', () => {
		expect(xpValue(1)).toBe(6);
		expect(xpValue(4)).toBe(12);
	});

	it('coin = 2 + floor(level / 2), capped at 6 on level 7', () => {
		expect(coinValue(1)).toBe(2);
		expect(coinValue(2)).toBe(3);
		expect(coinValue(6)).toBe(5);
		expect(coinValue(7)).toBe(6);
		expect(coinValue(8)).toBe(6); // 2 + floor(8/2) = 6, same
	});
});

describe('recommendedLevel (GameMethods port)', () => {
	it('defaults to 1 with no characters', () => {
		expect(recommendedLevel([], false)).toBe(1);
	});

	it('party: average level divided by 2, rounded up', () => {
		expect(recommendedLevel([2, 2, 2, 2], false)).toBe(1);
		expect(recommendedLevel([4, 4, 4, 4], false)).toBe(2);
		expect(recommendedLevel([3, 3, 3, 3], false)).toBe(2);
	});

	it('solo: (average + 1) / 2, rounded up', () => {
		expect(recommendedLevel([1], true)).toBe(1);
		expect(recommendedLevel([4], true)).toBe(3);
	});
});