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

41 lines
1.5 KiB
TypeScript
Raw Normal View History

2017-09-24 22:23:22 +00:00
module TK.SpaceTac.Specs {
2017-10-26 21:47:13 +00:00
testing("Target", test => {
test.case("initializes from ship or location", check => {
2015-02-06 00:00:00 +00:00
var target: Target;
target = Target.newFromLocation(2, 3);
2017-10-26 21:47:13 +00:00
check.equals(target.x, 2);
check.equals(target.y, 3);
check.equals(target.ship_id, null);
2015-02-06 00:00:00 +00:00
var ship = new Ship();
ship.arena_x = 4;
ship.arena_y = -2.1;
target = Target.newFromShip(ship);
2017-10-26 21:47:13 +00:00
check.equals(target.x, 4);
check.equals(target.y, -2.1);
check.equals(target.ship_id, ship.id);
2015-02-06 00:00:00 +00:00
});
2017-10-26 21:47:13 +00:00
test.case("gets distance to another target", check => {
2015-02-06 00:00:00 +00:00
var t1 = Target.newFromLocation(5, 1);
var t2 = Target.newFromLocation(6, 2);
2017-10-26 21:47:13 +00:00
check.nears(t1.getDistanceTo(t2), Math.sqrt(2));
2015-02-06 00:00:00 +00:00
});
2017-10-26 21:47:13 +00:00
test.case("gets angle to another target", check => {
2017-02-09 22:21:39 +00:00
var t1 = Target.newFromLocation(2, 3);
var t2 = Target.newFromLocation(4, 5);
2017-10-26 21:47:13 +00:00
check.nears(t1.getAngleTo(t2), Math.PI / 4);
2017-02-09 22:21:39 +00:00
});
2018-07-12 14:16:39 +00:00
test.case("snaps to a grid", check => {
let grid = new HexagonalArenaGrid(5, 1);
check.equals(Target.newFromLocation(1, 1).snap(grid), Target.newFromLocation(0, 0), "1,1");
check.equals(Target.newFromLocation(6, 4).snap(grid), Target.newFromLocation(7.5, 5), "6,4");
let ship = new Ship();
check.equals(new Target(6, 4, ship).snap(grid), new Target(7.5, 5, ship), "6,4,ship");
});
2015-02-06 00:00:00 +00:00
});
}