mirror of
https://github.com/db9979/wibosim.git
synced 2026-12-06 21:44:09 +01:00
Konflikte gelöst (Börsenneuling ins Index-Segment auch für Abspaltungen, Steuerarten, Rückzugsgründe, Journal, Admin, Stil). Prüf-Simulation: Buchungsarten spinoff, spinoffCash, merger, mergerCash und split im Hauptbuch (Barausgleich als Feld cash, Split skaliert Bots und Gegenbuchungen), Ereignisse Split, Zusammenlegung, Abspaltung und Fusion, Logo-Prüfung kennt reservierte Abspaltungen. Kein Split während einer laufenden Abspaltung oder Fusion. Erfolgs-Haken mit den vereinbarten Feldern. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018i4GUhQVoPUusUzxgxLWkK
47 lines
3.0 KiB
JavaScript
47 lines
3.0 KiB
JavaScript
// Prüf-Simulation, schnelle Variante für `npm test`: wenige Handelstage mit allen Ereignisarten (Rivalen, Börsengänge,
|
|
// Insolvenz/Abwicklung, Admin-Rückzug, Übernahme, Kapitalmaßnahmen, Split, Abspaltung, Fusion, Abend-/Wochenendhandel, Hebelprodukte, Fonds,
|
|
// Battles, Saisonende, Neustart und Absturz). Nach jedem Takt werden alle Invarianten geprüft (test/simkit.js).
|
|
// Der lange Lauf: `npm run soak -- --days 60 --seed 7`.
|
|
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import os from 'node:os';
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
process.env.NODE_ENV = 'test';
|
|
process.env.TIME_MODE = 'turbo';
|
|
process.env.DATA_DIR = fs.mkdtempSync(path.join(os.tmpdir(), 'wibosim-soakt-'));
|
|
const { runSoak } = await import('../test/soak-run.js');
|
|
const { MONEY, instrument } = await import('../test/simkit.js');
|
|
|
|
test('Prüf-Simulation: Invarianten über mehrere Handelstage mit allen Ereignisarten', { timeout: 120_000 }, async () => {
|
|
const rep = await runSoak({ days: 7, seed: 11, players: 6, restartEvery: 2, crashEvery: 3, seasonAt: 6, actionsPerTick: 5 });
|
|
assert.deepEqual(rep.fails, [], rep.fails.join('\n'));
|
|
assert.deepEqual(rep.warnings, []);
|
|
// die Ereignisse sind tatsächlich vorgekommen (sonst prüft der Lauf nichts)
|
|
for (const ev of ['insolvenz', 'adminRueckzug', 'uebernahme', 'kapitalerhoehung', 'rueckkauf', 'boersengang', 'indexpruefung', 'nachschuss', 'saisonende', 'split', 'zusammenlegung', 'abspaltung', 'fusion']) assert.ok(rep.events[ev] > 0, `Ereignis ${ev} kam nicht vor`);
|
|
for (const k of ['trade', 'auction', 'evening', 'ipo', 'delist', 'deriv', 'fund', 'tax', 'admin', 'split', 'spinoff', 'merger']) assert.ok(rep.kinds[k] > 0, `keine Buchung der Art ${k}`);
|
|
assert.ok(rep.counts['ok:order weekend'] > 0, 'Wochenendhandel');
|
|
assert.ok(rep.ipos >= 1, `Börsengänge ${rep.ipos}`);
|
|
for (const r of ['insolvency', 'admin', 'takeover']) assert.ok(rep.delistReasons[r] > 0, `kein Rückzug wegen ${r}: ${JSON.stringify(rep.delistReasons)}`);
|
|
assert.ok(rep.restarts >= 2 && rep.crashes >= 1, 'Neustarts');
|
|
assert.equal(rep.rivals, 3);
|
|
assert.ok(rep.counts.indexRueckzug >= 2 && rep.counts.indexUmbau >= 1, 'Index-Umbauten geprüft');
|
|
});
|
|
|
|
test('Prüf-Simulation: unbekannte Buchungsart und Geld aus dem Nichts werden erkannt', async () => {
|
|
const { Store } = await import('./store.js');
|
|
const { Game } = await import('./game.js');
|
|
const { checkAll } = await import('../test/simkit.js');
|
|
const g = new Game({ store: new Store(fs.mkdtempSync(path.join(os.tmpdir(), 'wibosim-soakn-'))), now: () => Date.UTC(2026, 0, 5, 7, 0) });
|
|
const p = (await g.register({ name: 'Negativ', password: 'geheim123' })).player;
|
|
const L = instrument(g);
|
|
checkAll(g, L, 'Start');
|
|
p.cash += 1;
|
|
assert.throws(() => checkAll(g, L, 'Geld'), /Geldmenge/);
|
|
p.cash -= 1;
|
|
g.recordFill({ ts: 0, owner: p.id, account: p.id, symbol: '-', side: 'fee', qty: 0, price: 0, fee: 0, realized: 0, kind: 'neuartig' });
|
|
assert.ok(!MONEY.neuartig);
|
|
assert.throws(() => checkAll(g, L, 'Art'), /ohne Geldregel/);
|
|
});
|