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

120 lines
5.6 KiB
TypeScript

module TK.SpaceTac.Specs {
testing("TurnPlanning", test => {
test.case("initializes from a battle state", check => {
let battle = new Battle();
let planning = new TurnPlanning(battle);
check.equals(planning.getTurnPlan(), {
fleets: [
{ fleet: battle.fleets[0].id, ships: [] },
{ fleet: battle.fleets[1].id, ships: [] },
]
});
battle.fleets[0].addShip();
planning = new TurnPlanning(battle);
check.equals(planning.getTurnPlan(), {
fleets: [
{
fleet: battle.fleets[0].id, ships: [
{ ship: battle.fleets[0].ships[0].id, actions: [] },
]
},
{ fleet: battle.fleets[1].id, ships: [] },
]
});
});
test.case("gets child fleet and ship plans", check => {
const battle = new Battle();
battle.fleets[0].addShip();
battle.fleets[1].addShip();
battle.fleets[1].addShip();
const planning = new TurnPlanning(battle);
check.equals(planning.getFleetPlan(battle.fleets[0]).fleet, battle.fleets[0].id);
check.equals(planning.getFleetPlan(battle.fleets[1]).fleet, battle.fleets[1].id);
check.equals(planning.getFleetPlan(new Fleet()).fleet, -1);
check.equals(planning.getShipPlan(battle.fleets[0].ships[0]).ship, battle.fleets[0].ships[0].id);
check.equals(planning.getShipPlan(battle.fleets[1].ships[0]).ship, battle.fleets[1].ships[0].id);
check.equals(planning.getShipPlan(battle.fleets[1].ships[1]).ship, battle.fleets[1].ships[1].id);
check.equals(planning.getShipPlan(new Ship()).ship, -1);
});
test.case("adds an action and target to a ship plan", check => {
const battle = new Battle();
const ship = battle.fleets[0].addShip();
const action1 = ship.actions.addCustom(new BaseAction());
const planning = new TurnPlanning(battle);
check.equals(planning.getShipPlan(ship).actions, []);
check.equals(planning.collectAllActions(), []);
planning.addAction(ship, action1, 100, 1);
check.equals(planning.getShipPlan(ship).actions, [
{ action: action1.id, category: action1.getCategory(), distance: 100, angle: 1 }
]);
check.equals(planning.collectAllActions(), [
{ action: action1.id, category: action1.getCategory(), distance: 100, angle: 1 }
]);
});
test.case("replaces existing actions", check => {
const battle = new Battle();
const ship = battle.fleets[0].addShip();
const action1 = ship.actions.addCustom(new BaseAction());
const action2 = ship.actions.addCustom(new BaseAction());
const planning = new TurnPlanning(battle);
check.equals(planning.getShipPlan(ship).actions, []);
planning.addAction(ship, action1);
check.equals(planning.getShipPlan(ship).actions, [
{ action: action1.id, category: action1.getCategory(), distance: undefined, angle: undefined }
]);
planning.addAction(ship, action2);
check.equals(planning.getShipPlan(ship).actions, [
{ action: action1.id, category: action1.getCategory(), distance: undefined, angle: undefined },
{ action: action2.id, category: action2.getCategory(), distance: undefined, angle: undefined }
]);
planning.addAction(ship, action1, 5);
check.equals(planning.getShipPlan(ship).actions, [
{ action: action2.id, category: action2.getCategory(), distance: undefined, angle: undefined },
{ action: action1.id, category: action1.getCategory(), distance: 5, angle: undefined }
]);
});
test.case("replaces other similar actions", check => {
const battle = new Battle();
const ship = battle.fleets[0].addShip();
const active1 = ship.actions.addCustom(new TriggerAction());
const active2 = ship.actions.addCustom(new TriggerAction());
const move1 = ship.actions.addCustom(new MoveAction());
const move2 = ship.actions.addCustom(new MoveAction());
const planning = new TurnPlanning(battle);
planning.addAction(ship, active1);
check.equals(planning.getShipPlan(ship).actions, [
{ action: active1.id, category: active1.getCategory(), distance: undefined, angle: undefined }
]);
planning.addAction(ship, active2);
check.equals(planning.getShipPlan(ship).actions, [
{ action: active2.id, category: active2.getCategory(), distance: undefined, angle: undefined }
]);
planning.addAction(ship, move1);
check.equals(planning.getShipPlan(ship).actions, [
{ action: active2.id, category: active2.getCategory(), distance: undefined, angle: undefined },
{ action: move1.id, category: move1.getCategory(), distance: undefined, angle: undefined }
]);
planning.addAction(ship, move2);
check.equals(planning.getShipPlan(ship).actions, [
{ action: active2.id, category: active2.getCategory(), distance: undefined, angle: undefined },
{ action: move2.id, category: move2.getCategory(), distance: undefined, angle: undefined }
]);
});
});
}