test: add unit tests for core game logic utilities
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m22s
Build and Publish Mana Loop Docker Image / build-and-publish (push) Successful in 1m22s
Add 5 new test files covering pure utility functions: - discipline-math.test.ts (42 tests): stat bonus, mana drain, perk tiers, discipline activation/progression, unlocked perks, discipline stats - formatting.test.ts (35 tests): fmt, fmtDec, formatSpellCost, getSpellCostColor, formatStudyTime, formatHour - floor-utils.test.ts (13 tests): getFloorMaxHP, getFloorElement - combat-utils.test.ts (37 tests): getElementalBonus, getBoonBonuses, getIncursionStrength, canAffordSpellCost, deductSpellCost - mana-utils.test.ts (36 tests): computeMaxMana, computeRegen, computeClickMana, getMeditationBonus, computeEffectiveRegenForDisplay Total: 163 new tests, all passing. No existing tests broken.
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { getFloorMaxHP, getFloorElement } from '../utils/floor-utils';
|
||||
|
||||
// ─── getFloorMaxHP ────────────────────────────────────────────────────────────
|
||||
|
||||
describe('getFloorMaxHP', () => {
|
||||
it('should return positive HP for floor 1', () => {
|
||||
expect(getFloorMaxHP(1)).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
it('should return base HP of 100 + scaling for floor 1', () => {
|
||||
// baseHP=100 + floorScaling=50 + exponentialScaling=1 = 151
|
||||
expect(getFloorMaxHP(1)).toBe(151);
|
||||
});
|
||||
|
||||
it('should scale with floor number', () => {
|
||||
const hp1 = getFloorMaxHP(1);
|
||||
const hp5 = getFloorMaxHP(5);
|
||||
const hp10 = getFloorMaxHP(10);
|
||||
expect(hp5).toBeGreaterThan(hp1);
|
||||
expect(hp10).toBeGreaterThan(hp5);
|
||||
});
|
||||
|
||||
it('should return much higher HP for guardian floors', () => {
|
||||
const hp9 = getFloorMaxHP(9);
|
||||
const hp10 = getFloorMaxHP(10); // Ignis Prime guardian
|
||||
expect(hp10).toBeGreaterThan(hp9 * 2);
|
||||
});
|
||||
|
||||
it('should handle high floors', () => {
|
||||
const hp100 = getFloorMaxHP(100);
|
||||
expect(hp100).toBeGreaterThan(0);
|
||||
expect(isFinite(hp100)).toBe(true);
|
||||
});
|
||||
|
||||
it('should be monotonically increasing for non-guardian floors', () => {
|
||||
let prev = getFloorMaxHP(1);
|
||||
for (let f = 2; f <= 9; f++) {
|
||||
const curr = getFloorMaxHP(f);
|
||||
expect(curr).toBeGreaterThan(prev);
|
||||
prev = curr;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// ─── getFloorElement ──────────────────────────────────────────────────────────
|
||||
|
||||
describe('getFloorElement', () => {
|
||||
it('should return a string element', () => {
|
||||
expect(typeof getFloorElement(1)).toBe('string');
|
||||
});
|
||||
|
||||
it('should return valid element names', () => {
|
||||
const validElements = ['fire', 'water', 'air', 'earth', 'light', 'dark', 'death'];
|
||||
for (let f = 1; f <= 20; f++) {
|
||||
expect(validElements).toContain(getFloorElement(f));
|
||||
}
|
||||
});
|
||||
|
||||
it('should cycle through 7 elements', () => {
|
||||
// Floor 1 and floor 8 should have the same element (cycle of 7)
|
||||
expect(getFloorElement(1)).toBe(getFloorElement(8));
|
||||
expect(getFloorElement(2)).toBe(getFloorElement(9));
|
||||
expect(getFloorElement(7)).toBe(getFloorElement(14));
|
||||
});
|
||||
|
||||
it('should return fire for floor 1', () => {
|
||||
expect(getFloorElement(1)).toBe('fire');
|
||||
});
|
||||
|
||||
it('should return water for floor 2', () => {
|
||||
expect(getFloorElement(2)).toBe('water');
|
||||
});
|
||||
|
||||
it('should return death for floor 7', () => {
|
||||
expect(getFloorElement(7)).toBe('death');
|
||||
});
|
||||
|
||||
it('should handle high floor numbers', () => {
|
||||
const elem = getFloorElement(100);
|
||||
expect(typeof elem).toBe('string');
|
||||
expect(elem.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user