1
0
Fork 0
spacetac/src/core/Target.spec.ts
2018-07-10 16:23:32 +02:00

33 lines
1.1 KiB
TypeScript

module TK.SpaceTac.Specs {
testing("Target", test => {
test.case("initializes from ship or location", check => {
var target: Target;
target = Target.newFromLocation(2, 3);
check.equals(target.x, 2);
check.equals(target.y, 3);
check.equals(target.ship_id, null);
var ship = new Ship();
ship.arena_x = 4;
ship.arena_y = -2.1;
target = Target.newFromShip(ship);
check.equals(target.x, 4);
check.equals(target.y, -2.1);
check.equals(target.ship_id, ship.id);
});
test.case("gets distance to another target", check => {
var t1 = Target.newFromLocation(5, 1);
var t2 = Target.newFromLocation(6, 2);
check.nears(t1.getDistanceTo(t2), Math.sqrt(2));
});
test.case("gets angle to another target", check => {
var t1 = Target.newFromLocation(2, 3);
var t2 = Target.newFromLocation(4, 5);
check.nears(t1.getAngleTo(t2), Math.PI / 4);
});
});
}