dd-timer/tests/regression/inventaire-simulation.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

59 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { describe, it, expect } from 'vitest';
import { simulateStock } from '@domain/services/StockSimulator';
import { BREEDING_RECIPES } from '@domain/value-objects/Race';
describe('Régression : simulation inventaire identique au monolithe', () => {
it('8 Rousse (4♂/4♀) + 8 Dorée (4♂/4♀) + 8 Amande (4♂/4♀) → 20 bébés sur 4 générations', () => {
const r = simulateStock({
Rousse: { m: 4, f: 4 },
Dorée: { m: 4, f: 4 },
Amande: { m: 4, f: 4 },
});
// Gen2 : 3 croisements × 4 bébés = 12
const gen2 = r.crossings.filter(c => c.gen === 2);
expect(gen2).toHaveLength(3);
expect(gen2.map(c => c.baby).sort()).toEqual(
['Amande et Dorée', 'Amande et Rousse', 'Dorée et Rousse'],
);
for (const c of gen2) expect(c.count).toBe(4);
// 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 reçoit 0 car EI alloué à floor(1/2)=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);
expect(r.crossings.reduce((s, c) => s + c.count, 0)).toBe(20);
});
it('la recette Ebène est 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('l\'algorithme glouton aurait donné 8 bébés sur 1 seule race — la version proportionnelle donne 12 sur 3 races', () => {
const r = simulateStock({
Rousse: { m: 4, f: 4 },
Dorée: { m: 4, f: 4 },
Amande: { m: 4, f: 4 },
});
// Vérifier qu'on ne voit PAS un seul croisement avec 8 bébés
for (const c of r.crossings.filter(x => x.gen === 2)) {
expect(c.count).toBeLessThanOrEqual(4);
}
expect(r.crossings.filter(c => c.gen === 2)).toHaveLength(3);
});
});