1
0
Fork 0
spacetac/src/core/TurnResolution.spec.ts

54 lines
2.2 KiB
TypeScript

module TK.SpaceTac {
testing("TurnResolution", test => {
test.case("defines play order by initiative throws", check => {
const fleet1 = new Fleet();
const fleet2 = new Fleet();
const ship1 = new Ship(fleet1, "F1S1");
TestTools.setAttribute(ship1, "initiative", 2);
const ship2 = new Ship(fleet1, "F1S2");
TestTools.setAttribute(ship2, "initiative", 4);
const ship3 = new Ship(fleet1, "F1S3");
TestTools.setAttribute(ship3, "initiative", 1);
const ship4 = new Ship(fleet2, "F2S1");
TestTools.setAttribute(ship4, "initiative", 8);
const ship5 = new Ship(fleet2, "F2S2");
TestTools.setAttribute(ship5, "initiative", 2);
const battle = new Battle(fleet1, fleet2);
const random = new SkewedRandomGenerator([1.0, 0.1, 1.0, 0.2, 0.6]);
const resolution = new TurnResolution(battle, { fleets: [] }, random);
check.equals(resolution.play_order, []);
resolution.throwInitiative();
check.equals(resolution.play_order, [ship1, ship4, ship5, ship3, ship2]);
});
test.case("logs a turn start diff", check => {
const battle = new Battle();
const resolution = new TurnResolution(battle, { fleets: [] });
const ships = [new Ship(), new Ship()]
resolution.play_order = ships;
check.equals(battle.log.count(), 0);
resolution.logStart();
check.equals(battle.log.count(), 1);
const diff = battle.log.get(0);
if (check.instance(diff, TurnStartDiff, "diff should be a TurnStartDiff")) {
check.equals(diff.play_order, [ships[0].id, ships[1].id]);
}
});
test.case("logs a turn end diff", check => {
const battle = new Battle();
const resolution = new TurnResolution(battle, { fleets: [] });
check.equals(battle.log.count(), 0);
resolution.logEnd();
check.equals(battle.log.count(), 1);
const diff = battle.log.get(0);
check.instance(diff, TurnEndDiff, "diff should be a TurnEndDiff");
});
});
}