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>
This commit is contained in:
57
tests/unit/domain/BreedingService.test.ts
Normal file
57
tests/unit/domain/BreedingService.test.ts
Normal file
@@ -0,0 +1,57 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { BreedingService } from '@domain/services/BreedingService';
|
||||
|
||||
describe('BreedingService', () => {
|
||||
const svc = new BreedingService();
|
||||
|
||||
it('deduces baby from two parents (order A)', () => {
|
||||
expect(svc.deduceBaby('Rousse', 'Dorée')).toBe('Dorée et Rousse');
|
||||
});
|
||||
|
||||
it('deduces baby from two parents (order B — bidirectional)', () => {
|
||||
expect(svc.deduceBaby('Dorée', 'Rousse')).toBe('Dorée et Rousse');
|
||||
});
|
||||
|
||||
it('returns null for incompatible parents', () => {
|
||||
expect(svc.deduceBaby('Rousse', 'Rousse')).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for unknown parents', () => {
|
||||
expect(svc.deduceBaby('Unknown', 'Dorée')).toBeNull();
|
||||
});
|
||||
|
||||
it('lists compatible partners for Rousse', () => {
|
||||
const partners = svc.getCompatiblePartners('Rousse');
|
||||
expect(partners.length).toBeGreaterThan(0);
|
||||
expect(partners.some(p => p.partner === 'Dorée')).toBe(true);
|
||||
expect(partners.some(p => p.partner === 'Amande')).toBe(true);
|
||||
});
|
||||
|
||||
it('returns empty array for unknown race', () => {
|
||||
expect(svc.getCompatiblePartners('Unknown')).toEqual([]);
|
||||
});
|
||||
|
||||
it('gets parents for a baby race', () => {
|
||||
const parents = svc.getParents('Dorée et Rousse');
|
||||
expect(parents).toEqual(['Rousse', 'Dorée']);
|
||||
});
|
||||
|
||||
it('returns null parents for base race', () => {
|
||||
expect(svc.getParents('Rousse')).toBeNull();
|
||||
});
|
||||
|
||||
it('gets generation of a race', () => {
|
||||
expect(svc.getGeneration('Rousse')).toBe(1);
|
||||
expect(svc.getGeneration('Dorée et Rousse')).toBe(2);
|
||||
});
|
||||
|
||||
it('all recipes are bidirectionally deducible', () => {
|
||||
// For every known recipe, both orderings should work
|
||||
const parents = svc.getParents('Amande et Dorée');
|
||||
expect(parents).not.toBeNull();
|
||||
if (parents) {
|
||||
expect(svc.deduceBaby(parents[0], parents[1])).toBe('Amande et Dorée');
|
||||
expect(svc.deduceBaby(parents[1], parents[0])).toBe('Amande et Dorée');
|
||||
}
|
||||
});
|
||||
});
|
||||
86
tests/unit/domain/Enclos.test.ts
Normal file
86
tests/unit/domain/Enclos.test.ts
Normal file
@@ -0,0 +1,86 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { createEnclos, addDragodinde, removeDragodinde, MAX_DD, MAX_ENCLOS, MAX_GAUGES } from '@domain/entities/Enclos';
|
||||
import { createDragodinde } from '@domain/entities/Dragodinde';
|
||||
import { createAccouplement } from '@domain/entities/Accouplement';
|
||||
|
||||
describe('Enclos', () => {
|
||||
it('creates with defaults', () => {
|
||||
const enc = createEnclos(1);
|
||||
expect(enc.id).toBe(1);
|
||||
expect(enc.name).toBe('Enclos 1');
|
||||
expect(enc.dragodindes).toHaveLength(0);
|
||||
expect(enc.activeGauges).toHaveLength(0);
|
||||
expect(enc.timer.running).toBe(false);
|
||||
expect(enc.gaugeLevels.baffeur).toBe(0);
|
||||
});
|
||||
|
||||
it('adds a dragodinde', () => {
|
||||
let enc = createEnclos(1);
|
||||
enc = addDragodinde(enc);
|
||||
expect(enc.dragodindes).toHaveLength(1);
|
||||
expect(enc.dragodindes[0]!.name).toBe('Dragodinde 1');
|
||||
expect(enc.nextDdId).toBe(2);
|
||||
});
|
||||
|
||||
it('increments DD id', () => {
|
||||
let enc = createEnclos(1);
|
||||
enc = addDragodinde(enc);
|
||||
enc = addDragodinde(enc);
|
||||
expect(enc.dragodindes[1]!.id).toBe(2);
|
||||
expect(enc.dragodindes[1]!.name).toBe('Dragodinde 2');
|
||||
});
|
||||
|
||||
it('limits to MAX_DD', () => {
|
||||
let enc = createEnclos(1);
|
||||
for (let i = 0; i < MAX_DD + 2; i++) enc = addDragodinde(enc);
|
||||
expect(enc.dragodindes).toHaveLength(MAX_DD);
|
||||
});
|
||||
|
||||
it('removes a dragodinde', () => {
|
||||
let enc = createEnclos(1);
|
||||
enc = addDragodinde(enc);
|
||||
const ddId = enc.dragodindes[0]!.id;
|
||||
enc = removeDragodinde(enc, ddId);
|
||||
expect(enc.dragodindes).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('remove non-existent DD is no-op', () => {
|
||||
let enc = createEnclos(1);
|
||||
enc = addDragodinde(enc);
|
||||
enc = removeDragodinde(enc, 999);
|
||||
expect(enc.dragodindes).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('constants are correct', () => {
|
||||
expect(MAX_DD).toBe(10);
|
||||
expect(MAX_ENCLOS).toBe(6);
|
||||
expect(MAX_GAUGES).toBe(2);
|
||||
});
|
||||
});
|
||||
|
||||
describe('Dragodinde', () => {
|
||||
it('creates with defaults', () => {
|
||||
const dd = createDragodinde(1);
|
||||
expect(dd.id).toBe(1);
|
||||
expect(dd.name).toBe('Dragodinde 1');
|
||||
expect(dd.gender).toBe('n');
|
||||
expect(dd.stats.serenite).toBe(0);
|
||||
expect(dd.stats.xp).toBe(1);
|
||||
expect(dd.targets.baffeur).toBe(-5000);
|
||||
expect(dd.sereniteTarget).toBeNull();
|
||||
expect(dd.levelTarget).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
describe('Accouplement', () => {
|
||||
it('creates with all fields', () => {
|
||||
const a = createAccouplement('Rousse', 'Dorée', 'Dorée et Rousse', 2, 5, 3);
|
||||
expect(a.parentA).toBe('Rousse');
|
||||
expect(a.parentB).toBe('Dorée');
|
||||
expect(a.baby).toBe('Dorée et Rousse');
|
||||
expect(a.gen).toBe(2);
|
||||
expect(a.couples).toBe(5);
|
||||
expect(a.babiesObtained).toBe(3);
|
||||
expect(a.date).toBeTruthy();
|
||||
});
|
||||
});
|
||||
45
tests/unit/domain/EventBus.test.ts
Normal file
45
tests/unit/domain/EventBus.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect, vi } from 'vitest';
|
||||
import { EventBus } from '@domain/events/EventBus';
|
||||
|
||||
describe('EventBus', () => {
|
||||
it('dispatches events to subscribers', () => {
|
||||
const bus = new EventBus();
|
||||
const handler = vi.fn();
|
||||
bus.on('timer-completed', handler);
|
||||
bus.emit({ type: 'timer-completed', enclosId: 1 });
|
||||
expect(handler).toHaveBeenCalledWith({ type: 'timer-completed', enclosId: 1 });
|
||||
});
|
||||
|
||||
it('ignores unsubscribed event types', () => {
|
||||
const bus = new EventBus();
|
||||
const handler = vi.fn();
|
||||
bus.on('timer-completed', handler);
|
||||
bus.emit({ type: 'accouplement-registered' });
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('supports multiple handlers for same event', () => {
|
||||
const bus = new EventBus();
|
||||
const h1 = vi.fn();
|
||||
const h2 = vi.fn();
|
||||
bus.on('timer-completed', h1);
|
||||
bus.on('timer-completed', h2);
|
||||
bus.emit({ type: 'timer-completed' });
|
||||
expect(h1).toHaveBeenCalled();
|
||||
expect(h2).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('off removes handler', () => {
|
||||
const bus = new EventBus();
|
||||
const handler = vi.fn();
|
||||
bus.on('timer-completed', handler);
|
||||
bus.off('timer-completed', handler);
|
||||
bus.emit({ type: 'timer-completed' });
|
||||
expect(handler).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('emit with no handlers does not throw', () => {
|
||||
const bus = new EventBus();
|
||||
expect(() => bus.emit({ type: 'timer-completed' })).not.toThrow();
|
||||
});
|
||||
});
|
||||
224
tests/unit/domain/GaugeCalculator.test.ts
Normal file
224
tests/unit/domain/GaugeCalculator.test.ts
Normal file
@@ -0,0 +1,224 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { gainedIn, timeToGain, gaugeAfter, elapsed, computeGaugeState, TimerState } from '@domain/services/GaugeCalculator';
|
||||
import type { GaugeRecharge } from '@domain/services/GaugeCalculator';
|
||||
|
||||
describe('GaugeCalculator', () => {
|
||||
|
||||
describe('gainedIn', () => {
|
||||
it('tier 1 only: 100 pts in 100 sec', () => {
|
||||
// Level 100, 100 sec = 10 ticks, rate 10 → gain 100
|
||||
expect(gainedIn(100, 100)).toBe(100);
|
||||
});
|
||||
|
||||
it('zero seconds = zero gain', () => {
|
||||
expect(gainedIn(50000, 0)).toBe(0);
|
||||
});
|
||||
|
||||
it('level 0 = zero gain', () => {
|
||||
expect(gainedIn(0, 100)).toBe(0);
|
||||
});
|
||||
|
||||
it('crosses tier boundary 2→1', () => {
|
||||
// Level 40010, 10 sec = 1 tick. In tier 2 (40001-70000), rate 20.
|
||||
// But only 10 pts above 40000, so 10/20 = 0 full ticks at rate 20 → 0 gained from tier 2
|
||||
// Actually: a = 40010-40000 = 10, m = floor(10/20) = 0, u = 0. Move to tier 1.
|
||||
// Tier 1: g=40010 > 0, a=40010-0=40010... wait g is now 40010 still since u=0
|
||||
// Let me recalculate: g=40010, tier {lo:40000, r:20}: a=10, m=0, u=0. No drain.
|
||||
// Tier {lo:0, r:10}: g=40010 > 0, a=40010, m=4001, u=min(4001,1)=1, out=10
|
||||
// Actually g should still be 40010 since we didn't drain. Hmm but the loop says if g<=lo continue
|
||||
// g=40010 > 40000 → process. a=10, m=floor(10/20)=0, u=0.
|
||||
// g=40010 > 0 → process. a=40010, m=floor(40010/10)=4001, u=min(4001,1)=1, out=10.
|
||||
expect(gainedIn(40010, 10)).toBe(10);
|
||||
});
|
||||
|
||||
it('full tier 4 drain', () => {
|
||||
// Level 100000, 250 ticks needed to drain tier 4 (10000/40=250)
|
||||
// 250 ticks = 2500 sec
|
||||
expect(gainedIn(100000, 2500)).toBe(10000);
|
||||
});
|
||||
|
||||
it('large gauge drains through multiple tiers', () => {
|
||||
// Level 100000, 5000 sec = 500 ticks
|
||||
// Tier 4: 100000→90000 = 10000/40 = 250 ticks → gain 10000, tl=250
|
||||
// Tier 3: 90000→70000 = 20000/30 = 666 ticks, but only 250 left → 250*30 = 7500
|
||||
// Total = 17500
|
||||
expect(gainedIn(100000, 5000)).toBe(17500);
|
||||
});
|
||||
|
||||
it('negative level clamped to 0', () => {
|
||||
expect(gainedIn(-100, 100)).toBe(0);
|
||||
});
|
||||
|
||||
it('level above 100000 clamped', () => {
|
||||
expect(gainedIn(150000, 10)).toBe(40); // tier 4 rate
|
||||
});
|
||||
});
|
||||
|
||||
describe('timeToGain', () => {
|
||||
it('zero points = zero time', () => {
|
||||
expect(timeToGain(50000, 0)).toBe(0);
|
||||
});
|
||||
|
||||
it('negative points = zero time', () => {
|
||||
expect(timeToGain(50000, -10)).toBe(0);
|
||||
});
|
||||
|
||||
it('tier 1: 100 pts needs 100 sec', () => {
|
||||
// Level 100, need 100 pts at rate 10 → 10 ticks → 100 sec
|
||||
expect(timeToGain(100, 100)).toBe(100);
|
||||
});
|
||||
|
||||
it('tier 2: 1000 pts from level 50000', () => {
|
||||
// Level 50000, tier 2 rate 20. 1000/20 = 50 ticks → 500 sec
|
||||
expect(timeToGain(50000, 1000)).toBe(500);
|
||||
});
|
||||
|
||||
it('returns Infinity if level is 0', () => {
|
||||
expect(timeToGain(0, 100)).toBe(Infinity);
|
||||
});
|
||||
});
|
||||
|
||||
describe('gaugeAfter', () => {
|
||||
it('no time = same level', () => {
|
||||
expect(gaugeAfter(50000, 0)).toBe(50000);
|
||||
});
|
||||
|
||||
it('tier 1 full drain', () => {
|
||||
// Level 100, 100 sec = 10 ticks. 100/10=10 ticks needed. Exactly drains to 0.
|
||||
expect(gaugeAfter(100, 100)).toBe(0);
|
||||
});
|
||||
|
||||
it('does not go below 0', () => {
|
||||
expect(gaugeAfter(50, 1000)).toBe(0);
|
||||
});
|
||||
|
||||
it('partial drain in tier 2', () => {
|
||||
// Level 50000, 10 sec = 1 tick. Rate 20 at tier 2. 50000-20 = 49980
|
||||
expect(gaugeAfter(50000, 10)).toBe(49980);
|
||||
});
|
||||
});
|
||||
|
||||
describe('computeGaugeState', () => {
|
||||
const NO_RECHARGES: GaugeRecharge[] = [];
|
||||
|
||||
it('sans recharge ni cap : identique à gainedIn', () => {
|
||||
const el = 1000;
|
||||
const startGl = 50000;
|
||||
const { gained, curGl, effectiveEl } = computeGaugeState(startGl, NO_RECHARGES, Infinity, el);
|
||||
expect(gained).toBe(gainedIn(startGl, el));
|
||||
expect(curGl).toBe(gaugeAfter(startGl, el));
|
||||
expect(effectiveEl).toBe(el);
|
||||
});
|
||||
|
||||
it('cap à 0 dès le départ (stat déjà au max) → gel immédiat', () => {
|
||||
const { gained, effectiveEl } = computeGaugeState(90000, NO_RECHARGES, 0, 5000);
|
||||
expect(gained).toBe(0);
|
||||
expect(effectiveEl).toBe(0);
|
||||
});
|
||||
|
||||
it('cap atteint en cours de segment → gel précis', () => {
|
||||
// Tier 2 (50000), rate 20/tick. On veut 200 pts → 10 ticks → 100 sec.
|
||||
const { gained, effectiveEl } = computeGaugeState(50000, NO_RECHARGES, 200, 5000);
|
||||
expect(gained).toBe(200);
|
||||
expect(effectiveEl).toBe(100); // timeToGain(50000, 200) = 100 sec
|
||||
});
|
||||
|
||||
it('une recharge avant la fin, pas de cap → somme des deux segments', () => {
|
||||
// Seg1 : 50000, 100 sec → gainedIn(50000, 100) = 10 ticks × 20 = 200 pts
|
||||
// Recharge à 80000 à t=100
|
||||
// Seg2 : 80000, 100 sec → gainedIn(80000, 100) = 10 ticks × 30 = 300 pts
|
||||
// Total = 500 pts
|
||||
const recharges: GaugeRecharge[] = [{ atSec: 100, level: 80000 }];
|
||||
const { gained, effectiveEl } = computeGaugeState(50000, recharges, Infinity, 200);
|
||||
expect(gained).toBe(500);
|
||||
expect(effectiveEl).toBe(200);
|
||||
});
|
||||
|
||||
it('cap atteint dans le premier segment (avant la recharge)', () => {
|
||||
// Seg1 : 50000, cap=100 pts → gel à timeToGain(50000,100)=50 sec
|
||||
// Recharge à t=100 ne doit pas être prise en compte
|
||||
const recharges: GaugeRecharge[] = [{ atSec: 100, level: 90000 }];
|
||||
const { gained, effectiveEl } = computeGaugeState(50000, recharges, 100, 500);
|
||||
expect(gained).toBe(100);
|
||||
expect(effectiveEl).toBe(50); // gel avant la recharge
|
||||
});
|
||||
|
||||
it('cap atteint dans le deuxième segment (après une recharge)', () => {
|
||||
// Seg1 : 50000, 100 sec → 200 pts, cap=500 → pas encore atteint
|
||||
// Recharge à 80000 à t=100
|
||||
// Seg2 : 80000, cap restant=300 pts → timeToGain(80000,300)=100 sec → effectiveEl=100+100=200
|
||||
const recharges: GaugeRecharge[] = [{ atSec: 100, level: 80000 }];
|
||||
const { gained, effectiveEl } = computeGaugeState(50000, recharges, 500, 9999);
|
||||
expect(gained).toBe(500);
|
||||
expect(effectiveEl).toBe(200);
|
||||
});
|
||||
|
||||
it('plusieurs recharges successives', () => {
|
||||
// Seg1 : 10000 (tier1), 50 sec → 5 ticks × 10 = 50 pts
|
||||
// Recharge à 50000 à t=50
|
||||
// Seg2 : 50000 (tier2), 50 sec → 5 ticks × 20 = 100 pts
|
||||
// Recharge à 90000 à t=100
|
||||
// Seg3 : 90000 (tier3), 50 sec → 5 ticks × 30 = 150 pts
|
||||
// Total = 300 pts
|
||||
const recharges: GaugeRecharge[] = [
|
||||
{ atSec: 50, level: 50000 },
|
||||
{ atSec: 100, level: 90000 },
|
||||
];
|
||||
const { gained } = computeGaugeState(10000, recharges, Infinity, 150);
|
||||
expect(gained).toBe(300);
|
||||
});
|
||||
|
||||
it('recharge après le cap → le cap prime, recharge ignorée', () => {
|
||||
// Cap à 50 pts → gel à 50 sec (tier2, rate20, 50/20=2.5→3 ticks=30sec... wait)
|
||||
// timeToGain(50000, 50) = ceil(50/20)*10 = 3*10 = 30 sec
|
||||
// Recharge à t=100 → ignorée car gel à t=30
|
||||
const recharges: GaugeRecharge[] = [{ atSec: 100, level: 90000 }];
|
||||
const { gained, effectiveEl } = computeGaugeState(50000, recharges, 50, 9999);
|
||||
expect(gained).toBe(50);
|
||||
expect(effectiveEl).toBe(30);
|
||||
});
|
||||
|
||||
it('curGl reflète le niveau après le gel', () => {
|
||||
// Tier2 (50000), cap=200 pts → 10 ticks → 100 sec, gauge = 50000-10*20=49800
|
||||
const { curGl } = computeGaugeState(50000, NO_RECHARGES, 200, 9999);
|
||||
expect(curGl).toBe(49800);
|
||||
});
|
||||
|
||||
it('curGl reflète la recharge dans le deuxième segment', () => {
|
||||
// Seg1: 50000, 100sec → curGl après seg1 = gaugeAfter(50000,100)=49800 mais recharge à 80000
|
||||
// Seg2: 80000, no cap → curGl = gaugeAfter(80000, 100sec) = 80000-10*30=79700
|
||||
const recharges: GaugeRecharge[] = [{ atSec: 100, level: 80000 }];
|
||||
const { curGl } = computeGaugeState(50000, recharges, Infinity, 200);
|
||||
expect(curGl).toBe(gaugeAfter(80000, 100));
|
||||
});
|
||||
});
|
||||
|
||||
describe('elapsed', () => {
|
||||
it('no start time = 0', () => {
|
||||
const t: TimerState = { startTime: null, running: false, pausedAt: null, pausedMs: 0 };
|
||||
expect(elapsed(t)).toBe(0);
|
||||
});
|
||||
|
||||
it('running timer', () => {
|
||||
const now = Date.now();
|
||||
const t: TimerState = { startTime: now - 10000, running: true, pausedAt: null, pausedMs: 0 };
|
||||
const el = elapsed(t);
|
||||
expect(el).toBeGreaterThanOrEqual(9.9);
|
||||
expect(el).toBeLessThanOrEqual(10.5);
|
||||
});
|
||||
|
||||
it('paused timer', () => {
|
||||
const now = Date.now();
|
||||
const t: TimerState = { startTime: now - 10000, running: false, pausedAt: now - 5000, pausedMs: 0 };
|
||||
const el = elapsed(t);
|
||||
expect(el).toBeCloseTo(5, 0);
|
||||
});
|
||||
|
||||
it('paused timer with accumulated pause', () => {
|
||||
const now = Date.now();
|
||||
const t: TimerState = { startTime: now - 20000, running: false, pausedAt: now - 5000, pausedMs: 5000 };
|
||||
// elapsed = (pausedAt - startTime - pausedMs) / 1000 = (15000 - 5000) / 1000 = 10
|
||||
expect(elapsed(t)).toBeCloseTo(10, 0);
|
||||
});
|
||||
});
|
||||
});
|
||||
45
tests/unit/domain/GaugeType.test.ts
Normal file
45
tests/unit/domain/GaugeType.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { GaugeType, GAUGE_DEFS, STAT_DEFS, DEFAULT_TARGETS, targetRange } from '@domain/value-objects/GaugeType';
|
||||
|
||||
describe('GaugeType', () => {
|
||||
it('should have 6 gauge types', () => {
|
||||
const types: GaugeType[] = ['baffeur', 'caresseur', 'foudroyeur', 'abreuvoir', 'dragofesse', 'mangeoire'];
|
||||
expect(types).toHaveLength(6);
|
||||
types.forEach(t => expect(GAUGE_DEFS[t]).toBeDefined());
|
||||
});
|
||||
|
||||
it('baffeur decreases serenite', () => {
|
||||
expect(GAUGE_DEFS.baffeur.stat).toBe('serenite');
|
||||
expect(GAUGE_DEFS.baffeur.dir).toBe(-1);
|
||||
});
|
||||
|
||||
it('caresseur increases serenite', () => {
|
||||
expect(GAUGE_DEFS.caresseur.stat).toBe('serenite');
|
||||
expect(GAUGE_DEFS.caresseur.dir).toBe(1);
|
||||
});
|
||||
|
||||
it('mangeoire is XP type', () => {
|
||||
expect(GAUGE_DEFS.mangeoire.isXp).toBe(true);
|
||||
expect(GAUGE_DEFS.mangeoire.stat).toBe('xp');
|
||||
});
|
||||
|
||||
it('STAT_DEFS has 5 stats', () => {
|
||||
expect(Object.keys(STAT_DEFS)).toHaveLength(5);
|
||||
});
|
||||
|
||||
it('targetRange for baffeur returns min:-5000 max:0', () => {
|
||||
expect(targetRange('baffeur')).toEqual({ min: -5000, max: 0 });
|
||||
});
|
||||
|
||||
it('targetRange for caresseur returns min:0 max:5000', () => {
|
||||
expect(targetRange('caresseur')).toEqual({ min: 0, max: 5000 });
|
||||
});
|
||||
|
||||
it('targetRange for mangeoire returns min:1 max:200', () => {
|
||||
expect(targetRange('mangeoire')).toEqual({ min: 1, max: 200 });
|
||||
});
|
||||
|
||||
it('targetRange for foudroyeur returns min:0 max:20000', () => {
|
||||
expect(targetRange('foudroyeur')).toEqual({ min: 0, max: 20000 });
|
||||
});
|
||||
});
|
||||
79
tests/unit/domain/InventaireCalculator.test.ts
Normal file
79
tests/unit/domain/InventaireCalculator.test.ts
Normal file
@@ -0,0 +1,79 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { InventaireCalculator } from '@domain/services/InventaireCalculator';
|
||||
|
||||
describe('InventaireCalculator', () => {
|
||||
const calc = new InventaireCalculator();
|
||||
|
||||
it('empty inventory produces nothing', () => {
|
||||
const r = calc.compute({});
|
||||
expect(r.generations).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('zero stock produces nothing', () => {
|
||||
const r = calc.compute({ 'Rousse': { m: 0, f: 0 } });
|
||||
expect(r.generations).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('\u2642 Rousse + \u2640 Dor\u00e9e produces Dor\u00e9e et Rousse', () => {
|
||||
const r = calc.compute({
|
||||
'Rousse': { m: 1, f: 0 },
|
||||
'Dor\u00e9e': { m: 0, f: 1 },
|
||||
});
|
||||
expect(r.generations.length).toBeGreaterThanOrEqual(1);
|
||||
const gen2 = r.generations.find(g => g.gen === 2);
|
||||
expect(gen2).toBeDefined();
|
||||
expect(gen2!.crossings.some(c => c.name === 'Dor\u00e9e et Rousse')).toBe(true);
|
||||
});
|
||||
|
||||
it('\u2640 Rousse + \u2642 Dor\u00e9e also produces (reversed genders)', () => {
|
||||
const r = calc.compute({
|
||||
'Rousse': { m: 0, f: 1 },
|
||||
'Dor\u00e9e': { m: 1, f: 0 },
|
||||
});
|
||||
const gen2 = r.generations.find(g => g.gen === 2);
|
||||
expect(gen2).toBeDefined();
|
||||
expect(gen2!.crossings.some(c => c.name === 'Dor\u00e9e et Rousse')).toBe(true);
|
||||
});
|
||||
|
||||
it('same gender cannot breed (\u2642+\u2642)', () => {
|
||||
const r = calc.compute({
|
||||
'Rousse': { m: 2, f: 0 },
|
||||
'Dor\u00e9e': { m: 2, f: 0 },
|
||||
});
|
||||
expect(r.generations).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('same gender cannot breed (\u2640+\u2640)', () => {
|
||||
const r = calc.compute({
|
||||
'Rousse': { m: 0, f: 2 },
|
||||
'Dor\u00e9e': { m: 0, f: 2 },
|
||||
});
|
||||
expect(r.generations).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('babies cascade to next generation', () => {
|
||||
const r = calc.compute({
|
||||
'Rousse': { m: 2, f: 2 },
|
||||
'Amande': { m: 2, f: 2 },
|
||||
'Dor\u00e9e': { m: 2, f: 2 },
|
||||
});
|
||||
const gen2 = r.generations.find(g => g.gen === 2);
|
||||
expect(gen2).toBeDefined();
|
||||
expect(gen2!.crossings.length).toBeGreaterThan(0);
|
||||
// Check if gen 3 exists (cascade from gen 2 babies)
|
||||
// This depends on whether gen 2 babies can breed with each other
|
||||
});
|
||||
|
||||
it('multiple pairs produce multiple babies', () => {
|
||||
const r = calc.compute({
|
||||
'Rousse': { m: 3, f: 3 },
|
||||
'Dor\u00e9e': { m: 3, f: 3 },
|
||||
});
|
||||
const gen2 = r.generations.find(g => g.gen === 2);
|
||||
expect(gen2).toBeDefined();
|
||||
const dr = gen2!.crossings.find(c => c.name === 'Dor\u00e9e et Rousse');
|
||||
expect(dr).toBeDefined();
|
||||
// With 3\u2642+3\u2640 of each, we can make up to 3 pairs (limited by one side)
|
||||
expect(dr!.qty).toBeGreaterThanOrEqual(3);
|
||||
});
|
||||
});
|
||||
60
tests/unit/domain/Race.test.ts
Normal file
60
tests/unit/domain/Race.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { RACE_GEN, GEN_COLORS, BREEDING_RECIPES, RACES_DATA, isBaseRace, generationOf, raceColor } from '@domain/value-objects/Race';
|
||||
import { Gender } from '@domain/value-objects/Gender';
|
||||
|
||||
describe('Race', () => {
|
||||
it('base races are gen 1', () => {
|
||||
expect(generationOf('Rousse')).toBe(1);
|
||||
expect(generationOf('Amande')).toBe(1);
|
||||
expect(generationOf('Dorée')).toBe(1);
|
||||
expect(isBaseRace('Rousse')).toBe(true);
|
||||
});
|
||||
|
||||
it('gen 2 races are correctly mapped', () => {
|
||||
expect(generationOf('Dorée et Rousse')).toBe(2);
|
||||
expect(generationOf('Amande et Dorée')).toBe(2);
|
||||
expect(generationOf('Amande et Rousse')).toBe(2);
|
||||
expect(isBaseRace('Dorée et Rousse')).toBe(false);
|
||||
});
|
||||
|
||||
it('GEN_COLORS has 10 entries', () => {
|
||||
expect(Object.keys(GEN_COLORS)).toHaveLength(10);
|
||||
});
|
||||
|
||||
it('BREEDING_RECIPES maps baby to parents', () => {
|
||||
expect(BREEDING_RECIPES['Dorée et Rousse']).toEqual(['Rousse', 'Dorée']);
|
||||
expect(BREEDING_RECIPES['Amande et Dorée']).toEqual(['Amande', 'Dorée']);
|
||||
});
|
||||
|
||||
it('Ebène = Amande et Dorée + Dorée et Rousse (pas Amande et Rousse)', () => {
|
||||
expect(BREEDING_RECIPES['Ebène']).toEqual(['Amande et Dorée', 'Dorée et Rousse']);
|
||||
});
|
||||
|
||||
it('RACES_DATA has generations 2-10', () => {
|
||||
for (let g = 2; g <= 10; g++) {
|
||||
expect(RACES_DATA[g]).toBeDefined();
|
||||
expect(RACES_DATA[g]!.length).toBeGreaterThan(0);
|
||||
}
|
||||
});
|
||||
|
||||
it('raceColor returns a color string', () => {
|
||||
expect(raceColor('Rousse')).toBe('#c8622a');
|
||||
expect(raceColor('Dorée')).toBe('#e8b820');
|
||||
expect(raceColor('Unknown')).toBe('#888');
|
||||
});
|
||||
|
||||
it('all breeding recipes have valid parents in RACE_GEN', () => {
|
||||
for (const [baby, [pA, pB]] of Object.entries(BREEDING_RECIPES)) {
|
||||
expect(RACE_GEN[baby]).toBeDefined();
|
||||
expect(RACE_GEN[pA]).toBeDefined();
|
||||
expect(RACE_GEN[pB]).toBeDefined();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe('Gender', () => {
|
||||
it('has male, female, neutral', () => {
|
||||
const values: Gender[] = ['m', 'f', 'n'];
|
||||
expect(values).toHaveLength(3);
|
||||
});
|
||||
});
|
||||
49
tests/unit/domain/ReapproCalculator.test.ts
Normal file
49
tests/unit/domain/ReapproCalculator.test.ts
Normal file
@@ -0,0 +1,49 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ReapproCalculator } from '@domain/services/ReapproCalculator';
|
||||
|
||||
describe('ReapproCalculator', () => {
|
||||
const calc = new ReapproCalculator();
|
||||
|
||||
it('empty target returns empty', () => {
|
||||
const r = calc.compute({ target: '', qty: 1, repro: {}, inverted: {} });
|
||||
expect(r.steps).toHaveLength(0);
|
||||
expect(r.gen1Needs).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('unknown target returns empty', () => {
|
||||
const r = calc.compute({ target: 'Unknown', qty: 1, repro: {}, inverted: {} });
|
||||
expect(r.steps).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('gen2 race needs 2 gen1 parents', () => {
|
||||
const r = calc.compute({ target: 'Dorée et Rousse', qty: 4, repro: {}, inverted: {} });
|
||||
expect(r.steps).toHaveLength(1);
|
||||
expect(r.steps[0]!.parentA).toBe('Rousse');
|
||||
expect(r.steps[0]!.parentB).toBe('Dorée');
|
||||
expect(r.steps[0]!.couples).toBe(4);
|
||||
expect(r.gen1Needs).toHaveLength(2);
|
||||
expect(r.totalGen1).toBe(8); // 4 Rousse + 4 Dorée
|
||||
});
|
||||
|
||||
it('gender inversion swaps parents', () => {
|
||||
const r = calc.compute({ target: 'Dorée et Rousse', qty: 4, repro: {}, inverted: { 'Dorée et Rousse': true } });
|
||||
expect(r.steps[0]!.parentA).toBe('Dorée');
|
||||
expect(r.steps[0]!.parentB).toBe('Rousse');
|
||||
});
|
||||
|
||||
it('breeders reduce couple count', () => {
|
||||
const r = calc.compute({ target: 'Dorée et Rousse', qty: 4, repro: { 'Dorée et Rousse': 2 }, inverted: {} });
|
||||
expect(r.steps[0]!.couples).toBe(2);
|
||||
});
|
||||
|
||||
it('gen1 needs include male/female split', () => {
|
||||
const r = calc.compute({ target: 'Dorée et Rousse', qty: 2, repro: {}, inverted: {} });
|
||||
const rousse = r.gen1Needs.find(n => n.name === 'Rousse');
|
||||
const doree = r.gen1Needs.find(n => n.name === 'Dorée');
|
||||
expect(rousse).toBeDefined();
|
||||
expect(doree).toBeDefined();
|
||||
// Default: parentA (Rousse) = male, parentB (Dorée) = female
|
||||
expect(rousse!.m).toBe(2);
|
||||
expect(doree!.f).toBe(2);
|
||||
});
|
||||
});
|
||||
42
tests/unit/domain/SerenityCalculator.test.ts
Normal file
42
tests/unit/domain/SerenityCalculator.test.ts
Normal file
@@ -0,0 +1,42 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { SerenityCalculator } from '@domain/services/SerenityCalculator';
|
||||
|
||||
describe('SerenityCalculator', () => {
|
||||
const calc = new SerenityCalculator();
|
||||
|
||||
it('null target → not done, 0 seconds', () => {
|
||||
const r = calc.computeEta({ currentSerenite: 0, target: null, activeGauges: [], gaugeLevels: {} });
|
||||
expect(r.done).toBe(false);
|
||||
expect(r.seconds).toBe(0);
|
||||
});
|
||||
|
||||
it('target already reached → done', () => {
|
||||
const r = calc.computeEta({ currentSerenite: -5000, target: -5000, activeGauges: ['baffeur'], gaugeLevels: { baffeur: 50000 } });
|
||||
expect(r.done).toBe(true);
|
||||
});
|
||||
|
||||
it('needs baffeur to decrease serenite', () => {
|
||||
const r = calc.computeEta({ currentSerenite: 0, target: -5000, activeGauges: [], gaugeLevels: {} });
|
||||
expect(r.needsGauge).toBe('baffeur');
|
||||
expect(r.seconds).toBe(Infinity);
|
||||
});
|
||||
|
||||
it('needs caresseur to increase serenite', () => {
|
||||
const r = calc.computeEta({ currentSerenite: 0, target: 40, activeGauges: [], gaugeLevels: {} });
|
||||
expect(r.needsGauge).toBe('caresseur');
|
||||
});
|
||||
|
||||
it('computes time with baffeur active', () => {
|
||||
const r = calc.computeEta({ currentSerenite: 0, target: -100, activeGauges: ['baffeur'], gaugeLevels: { baffeur: 50000 } });
|
||||
expect(r.done).toBe(false);
|
||||
expect(r.seconds).toBeGreaterThan(0);
|
||||
expect(r.seconds).toBeLessThan(Infinity);
|
||||
});
|
||||
|
||||
it('computes time with caresseur active', () => {
|
||||
const r = calc.computeEta({ currentSerenite: 0, target: 100, activeGauges: ['caresseur'], gaugeLevels: { caresseur: 50000 } });
|
||||
expect(r.done).toBe(false);
|
||||
expect(r.seconds).toBeGreaterThan(0);
|
||||
expect(r.seconds).toBeLessThan(Infinity);
|
||||
});
|
||||
});
|
||||
163
tests/unit/domain/StockSimulator.test.ts
Normal file
163
tests/unit/domain/StockSimulator.test.ts
Normal file
@@ -0,0 +1,163 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { simulateStock } from '@domain/services/StockSimulator';
|
||||
|
||||
describe('simulateStock', () => {
|
||||
it('stock vide → aucun croisement', () => {
|
||||
const r = simulateStock({});
|
||||
expect(r.crossings).toHaveLength(0);
|
||||
expect(r.unusedStock).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('stock à zéro → aucun croisement', () => {
|
||||
const r = simulateStock({ Rousse: { m: 0, f: 0 } });
|
||||
expect(r.crossings).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('♂Rousse + ♀Dorée → Dorée et Rousse ×1 (config1)', () => {
|
||||
const r = simulateStock({ Rousse: { m: 1, f: 0 }, Dorée: { m: 0, f: 1 } });
|
||||
expect(r.crossings).toHaveLength(1);
|
||||
expect(r.crossings[0]!.baby).toBe('Dorée et Rousse');
|
||||
expect(r.crossings[0]!.count).toBe(1);
|
||||
expect(r.crossings[0]!.pAMale).toBe(1); // ♂Rousse
|
||||
expect(r.crossings[0]!.pAFemale).toBe(0);
|
||||
expect(r.crossings[0]!.pBFemale).toBe(1); // ♀Dorée
|
||||
expect(r.crossings[0]!.pBMale).toBe(0);
|
||||
});
|
||||
|
||||
it('♀Rousse + ♂Dorée → Dorée et Rousse ×1 (config2)', () => {
|
||||
const r = simulateStock({ Rousse: { m: 0, f: 1 }, Dorée: { m: 1, f: 0 } });
|
||||
expect(r.crossings).toHaveLength(1);
|
||||
expect(r.crossings[0]!.baby).toBe('Dorée et Rousse');
|
||||
expect(r.crossings[0]!.count).toBe(1);
|
||||
expect(r.crossings[0]!.pAMale).toBe(0);
|
||||
expect(r.crossings[0]!.pAFemale).toBe(1); // ♀Rousse config2
|
||||
});
|
||||
|
||||
it('♂♂Rousse + ♀♀Dorée (même sexe d\'un côté) → 2 bébés config1 seulement', () => {
|
||||
const r = simulateStock({ Rousse: { m: 2, f: 0 }, Dorée: { m: 0, f: 2 } });
|
||||
expect(r.crossings).toHaveLength(1);
|
||||
expect(r.crossings[0]!.count).toBe(2);
|
||||
expect(r.crossings[0]!.pAMale).toBe(2); // 2× ♂Rousse × ♀Dorée
|
||||
expect(r.crossings[0]!.pAFemale).toBe(0); // pas de config2
|
||||
});
|
||||
|
||||
it('les deux configs simultanées : 2♂/2♀ × 2♂/2♀ → 4 bébés', () => {
|
||||
const r = simulateStock({ Rousse: { m: 2, f: 2 }, Dorée: { m: 2, f: 2 } });
|
||||
const c = r.crossings.find(x => x.baby === 'Dorée et Rousse');
|
||||
expect(c).toBeDefined();
|
||||
expect(c!.count).toBe(4);
|
||||
expect(c!.pAMale).toBe(2); // c1 = min(♂R=2, ♀D=2)
|
||||
expect(c!.pAFemale).toBe(2); // c2 = min(♀R=2, ♂D=2)
|
||||
});
|
||||
|
||||
it('distribution proportionnelle : 4♂/4♀ × 3 races → 4 bébés par croisement Gen2', () => {
|
||||
const r = simulateStock({
|
||||
Rousse: { m: 4, f: 4 },
|
||||
Dorée: { m: 4, f: 4 },
|
||||
Amande: { m: 4, f: 4 },
|
||||
});
|
||||
const gen2 = r.crossings.filter(c => c.gen === 2);
|
||||
expect(gen2).toHaveLength(3);
|
||||
for (const c of gen2) {
|
||||
expect(c.count).toBe(4);
|
||||
}
|
||||
});
|
||||
|
||||
it('cascade complète Gen2→Gen3→Gen4→Gen5 avec 4♂/4♀ × 3 races', () => {
|
||||
const r = simulateStock({
|
||||
Rousse: { m: 4, f: 4 },
|
||||
Dorée: { m: 4, f: 4 },
|
||||
Amande: { m: 4, f: 4 },
|
||||
});
|
||||
|
||||
// Gen2 : AmR×4, DorR×4, AmD×4 = 12
|
||||
const gen2 = r.crossings.filter(c => c.gen === 2);
|
||||
expect(gen2.reduce((s, c) => s + c.count, 0)).toBe(12);
|
||||
|
||||
// Gen3 : Ebène×2, Indigo×2 = 4
|
||||
const gen3 = r.crossings.filter(c => c.gen === 3);
|
||||
expect(gen3).toHaveLength(2);
|
||||
expect(gen3.find(c => c.baby === 'Ebène')!.count).toBe(2);
|
||||
expect(gen3.find(c => c.baby === 'Indigo')!.count).toBe(2);
|
||||
|
||||
// Gen4 : Ebène et Indigo×2
|
||||
const gen4 = r.crossings.filter(c => c.gen === 4);
|
||||
expect(gen4).toHaveLength(1);
|
||||
expect(gen4[0]!.baby).toBe('Ebène et Indigo');
|
||||
expect(gen4[0]!.count).toBe(2);
|
||||
|
||||
// Gen5 : Orchidée×2 (Pourpre ignoré car EI allocation = 0)
|
||||
const gen5 = r.crossings.filter(c => c.gen === 5);
|
||||
expect(gen5).toHaveLength(1);
|
||||
expect(gen5[0]!.baby).toBe('Orchidée');
|
||||
expect(gen5[0]!.count).toBe(2);
|
||||
|
||||
// Total : 12 + 4 + 2 + 2 = 20
|
||||
const total = r.crossings.reduce((s, c) => s + c.count, 0);
|
||||
expect(total).toBe(20);
|
||||
});
|
||||
|
||||
it('allocation proportionnelle donne la priorité au second croisement quand le premier reçoit 0', () => {
|
||||
// EI participe à Pourpre (1er) et Orchidée (2nd) en Gen5
|
||||
// Avec 1♂/1♀ EI, alloc = floor(1/2) = 0 pour Pourpre → 0 bébés
|
||||
// Orchidée : EI n'a plus qu'1 croisement restant → alloc = 1 → 2 bébés
|
||||
const r = simulateStock({
|
||||
'Ebène et Indigo': { m: 1, f: 1 },
|
||||
'Amande et Rousse': { m: 1, f: 1 },
|
||||
'Dorée et Rousse': { m: 1, f: 1 },
|
||||
});
|
||||
expect(r.crossings.find(c => c.baby === 'Pourpre')).toBeUndefined();
|
||||
expect(r.crossings.find(c => c.baby === 'Orchidée')?.count).toBe(2);
|
||||
});
|
||||
|
||||
it('race sans partenaire → stock inutilisé', () => {
|
||||
const r = simulateStock({ Rousse: { m: 5, f: 5 } });
|
||||
expect(r.crossings).toHaveLength(0);
|
||||
expect(r.unusedStock).toHaveLength(1);
|
||||
expect(r.unusedStock[0]!.race).toBe('Rousse');
|
||||
expect(r.unusedStock[0]!.m).toBe(5);
|
||||
expect(r.unusedStock[0]!.f).toBe(5);
|
||||
});
|
||||
|
||||
it('stock restant après simulation correctement identifié', () => {
|
||||
// 1♂ Rousse + 1♀ Dorée → 1 DorR. Rousse ♀ = 3 restantes
|
||||
const r = simulateStock({ Rousse: { m: 1, f: 3 }, Dorée: { m: 0, f: 1 } });
|
||||
expect(r.crossings).toHaveLength(1);
|
||||
expect(r.crossings[0]!.count).toBe(1);
|
||||
const leftR = r.unusedStock.find(u => u.race === 'Rousse');
|
||||
expect(leftR).toBeDefined();
|
||||
expect(leftR!.f).toBe(3);
|
||||
});
|
||||
|
||||
it('bébés répartis ♂/♀ pour les générations suivantes', () => {
|
||||
// 1♂/1♀ Rousse + 1♂/1♀ Dorée → 2 DorR (1♂, 1♀)
|
||||
// 1♂/1♀ Amande + 1♂/1♀ Rousse_new? Non, Amande n'a pas de stock
|
||||
const r = simulateStock({ Rousse: { m: 1, f: 1 }, Dorée: { m: 1, f: 1 } });
|
||||
expect(r.crossings).toHaveLength(1);
|
||||
expect(r.crossings[0]!.count).toBe(2);
|
||||
// Bébés DorR dans unused : 1♂ + 1♀
|
||||
const baby = r.unusedStock.find(u => u.race === 'Dorée et Rousse');
|
||||
expect(baby).toBeDefined();
|
||||
expect(baby!.m).toBe(1);
|
||||
expect(baby!.f).toBe(1);
|
||||
});
|
||||
|
||||
it('ne modifie pas l\'inventaire d\'entrée (immutabilité)', () => {
|
||||
const inv = { Rousse: { m: 2, f: 2 }, Dorée: { m: 2, f: 2 } };
|
||||
simulateStock(inv);
|
||||
expect(inv.Rousse.m).toBe(2);
|
||||
expect(inv.Rousse.f).toBe(2);
|
||||
expect(inv.Dorée.m).toBe(2);
|
||||
expect(inv.Dorée.f).toBe(2);
|
||||
});
|
||||
|
||||
it('stock asymétrique : 3♂/1♀ Rousse + 1♂/3♀ Dorée', () => {
|
||||
const r = simulateStock({ Rousse: { m: 3, f: 1 }, Dorée: { m: 1, f: 3 } });
|
||||
const c = r.crossings.find(x => x.baby === 'Dorée et Rousse');
|
||||
expect(c).toBeDefined();
|
||||
// c1 = min(♂R=3, ♀D=3) = 3, c2 = min(♀R=1, ♂D=1) = 1 → bred = 4
|
||||
expect(c!.count).toBe(4);
|
||||
expect(c!.pAMale).toBe(3);
|
||||
expect(c!.pAFemale).toBe(1);
|
||||
});
|
||||
});
|
||||
34
tests/unit/domain/Tier.test.ts
Normal file
34
tests/unit/domain/Tier.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { tierRate, tierNum, TIER_THRESHOLDS } from '@domain/value-objects/Tier';
|
||||
|
||||
describe('Tier', () => {
|
||||
it('tier 1: level 0-40000, rate 10', () => {
|
||||
expect(tierRate(0)).toBe(10);
|
||||
expect(tierRate(39999)).toBe(10);
|
||||
expect(tierRate(40000)).toBe(10);
|
||||
expect(tierNum(0)).toBe(1);
|
||||
expect(tierNum(40000)).toBe(1);
|
||||
});
|
||||
|
||||
it('tier 2: level 40001-70000, rate 20', () => {
|
||||
expect(tierRate(40001)).toBe(20);
|
||||
expect(tierRate(70000)).toBe(20);
|
||||
expect(tierNum(50000)).toBe(2);
|
||||
});
|
||||
|
||||
it('tier 3: level 70001-90000, rate 30', () => {
|
||||
expect(tierRate(70001)).toBe(30);
|
||||
expect(tierRate(90000)).toBe(30);
|
||||
expect(tierNum(80000)).toBe(3);
|
||||
});
|
||||
|
||||
it('tier 4: level 90001+, rate 40', () => {
|
||||
expect(tierRate(90001)).toBe(40);
|
||||
expect(tierRate(100000)).toBe(40);
|
||||
expect(tierNum(95000)).toBe(4);
|
||||
});
|
||||
|
||||
it('TIER_THRESHOLDS has 4 entries', () => {
|
||||
expect(TIER_THRESHOLDS).toHaveLength(4);
|
||||
});
|
||||
});
|
||||
41
tests/unit/domain/XpCalculator.test.ts
Normal file
41
tests/unit/domain/XpCalculator.test.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { XpCalculator } from '@domain/services/XpCalculator';
|
||||
|
||||
describe('XpCalculator', () => {
|
||||
const calc = new XpCalculator();
|
||||
|
||||
it('null target → not done, 0 seconds', () => {
|
||||
const r = calc.computeEta({ currentLevel: 1, target: null, gaugeLevels: {}, activeGauges: [] });
|
||||
expect(r.done).toBe(false);
|
||||
expect(r.seconds).toBe(0);
|
||||
});
|
||||
|
||||
it('level already reached → done', () => {
|
||||
const r = calc.computeEta({ currentLevel: 100, target: 100, gaugeLevels: { mangeoire: 50000 }, activeGauges: ['mangeoire'] });
|
||||
expect(r.done).toBe(true);
|
||||
});
|
||||
|
||||
it('level above target → done', () => {
|
||||
const r = calc.computeEta({ currentLevel: 150, target: 100, gaugeLevels: { mangeoire: 50000 }, activeGauges: ['mangeoire'] });
|
||||
expect(r.done).toBe(true);
|
||||
});
|
||||
|
||||
it('needs mangeoire gauge', () => {
|
||||
const r = calc.computeEta({ currentLevel: 1, target: 100, gaugeLevels: {}, activeGauges: [] });
|
||||
expect(r.needsGauge).toBe('mangeoire');
|
||||
expect(r.seconds).toBe(Infinity);
|
||||
});
|
||||
|
||||
it('computes seconds to level up', () => {
|
||||
const r = calc.computeEta({ currentLevel: 1, target: 10, gaugeLevels: { mangeoire: 50000 }, activeGauges: ['mangeoire'] });
|
||||
expect(r.done).toBe(false);
|
||||
expect(r.seconds).toBeGreaterThan(0);
|
||||
expect(r.seconds).toBeLessThan(Infinity);
|
||||
});
|
||||
|
||||
it('regression: should NOT show ~23h for short XP gain', () => {
|
||||
// Bug v1.1.4: timer displayed ~23h instead of real time
|
||||
const r = calc.computeEta({ currentLevel: 1, target: 5, gaugeLevels: { mangeoire: 50000 }, activeGauges: ['mangeoire'] });
|
||||
expect(r.seconds).toBeLessThan(3600); // Must be under 1h
|
||||
});
|
||||
});
|
||||
45
tests/unit/domain/XpTable.test.ts
Normal file
45
tests/unit/domain/XpTable.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { XP_RAW, xpForLevel, levelFromXp } from '@domain/value-objects/XpTable';
|
||||
|
||||
describe('XpTable', () => {
|
||||
it('has 200 entries', () => {
|
||||
expect(Object.keys(XP_RAW)).toHaveLength(200);
|
||||
});
|
||||
|
||||
it('level 1 requires 0 XP', () => {
|
||||
expect(xpForLevel(1)).toBe(0);
|
||||
});
|
||||
|
||||
it('level 200 requires 867582 XP', () => {
|
||||
expect(xpForLevel(200)).toBe(867582);
|
||||
});
|
||||
|
||||
it('clamps below 1', () => {
|
||||
expect(xpForLevel(0)).toBe(0);
|
||||
expect(xpForLevel(-5)).toBe(0);
|
||||
});
|
||||
|
||||
it('clamps above 200', () => {
|
||||
expect(xpForLevel(250)).toBe(867582);
|
||||
});
|
||||
|
||||
it('levelFromXp returns correct level', () => {
|
||||
expect(levelFromXp(0)).toBe(1);
|
||||
expect(levelFromXp(18)).toBe(1);
|
||||
expect(levelFromXp(19)).toBe(2);
|
||||
expect(levelFromXp(867582)).toBe(200);
|
||||
expect(levelFromXp(999999)).toBe(200);
|
||||
});
|
||||
|
||||
it('roundtrip: xpForLevel → levelFromXp', () => {
|
||||
for (let lvl = 1; lvl <= 200; lvl++) {
|
||||
expect(levelFromXp(xpForLevel(lvl))).toBe(lvl);
|
||||
}
|
||||
});
|
||||
|
||||
it('XP values are monotonically increasing', () => {
|
||||
for (let lvl = 2; lvl <= 200; lvl++) {
|
||||
expect(XP_RAW[lvl]!).toBeGreaterThan(XP_RAW[lvl - 1]!);
|
||||
}
|
||||
});
|
||||
});
|
||||
7
tests/unit/domain/smoke.test.ts
Normal file
7
tests/unit/domain/smoke.test.ts
Normal file
@@ -0,0 +1,7 @@
|
||||
import { describe, it, expect } from 'vitest';
|
||||
|
||||
describe('smoke test', () => {
|
||||
it('should run', () => {
|
||||
expect(1 + 1).toBe(2);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user