dd-timer/tests/regression/gauge-tier-calculation.test.ts
POL Mickaël 203c423f19 test: 302 tests unitaires + 20 E2E Playwright (couverture 94%)
- Unit : domain (GaugeCalculator, Enclos, Dragodinde, XpTable, Race, Tier...)
- Unit : application (commands, queries, CommandBus)
- Fonctionnel : breeding-workflow, enclos-management, timer-workflow
- Régression : gauge-tier, gauge-recharge, xp-timer, level-target, breeding
- E2E Playwright + Electron : navigation, timer, recharge jauge,
  accouplement, persistance des données

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-06 05:43:29 +02:00

38 lines
1.4 KiB
TypeScript

import { describe, it, expect } from 'vitest';
import { gainedIn, timeToGain, gaugeAfter } from '@domain/services/GaugeCalculator';
describe('Regression: Gauge tier calculations', () => {
it('gaugeAfter is inverse of gainedIn', () => {
// For a given level and time, gaugeAfter should equal level - gainedIn
const level = 80000;
const sec = 100; // 10 ticks
const gained = gainedIn(level, sec);
const after = gaugeAfter(level, sec);
expect(after).toBe(level - gained);
});
it('timeToGain matches gainedIn for exact amounts', () => {
// If gainedIn(50000, 100) = X, then timeToGain(50000, X) should be <= 100
const level = 50000;
const sec = 100;
const gained = gainedIn(level, sec);
if (gained > 0) {
const time = timeToGain(level, gained);
expect(time).toBeLessThanOrEqual(sec);
}
});
it('boundary: level exactly at tier threshold', () => {
// Level 40000 = tier 1 (<=40000), rate 10
expect(gaugeAfter(40000, 10)).toBe(39990); // 1 tick at rate 10
// Level 40001 = tier 2 (>40000), but only 1 pt above threshold
// 1 pt in tier 2 zone: floor(1/20)=0 ticks consumed there, falls through to tier 1
expect(gaugeAfter(40001, 10)).toBe(39991); // 1 tick at rate 10 in tier 1 zone
});
it('does not produce negative values', () => {
expect(gaugeAfter(10, 100000)).toBe(0);
expect(gainedIn(10, 100000)).toBe(10);
});
});