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);
|
2017-11-14 00:07:06 +00:00
|
|
|
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);
|
2017-11-14 00:07:06 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("checks if a target is in range of another", check => {
|
2015-02-06 00:00:00 +00:00
|
|
|
var t1 = Target.newFromLocation(5, 4);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(t1.isInRange(7, 3, 2), false);
|
|
|
|
check.equals(t1.isInRange(7, 3, 3), true);
|
|
|
|
check.equals(t1.isInRange(5, 5, 2), true);
|
2015-02-06 00:00:00 +00:00
|
|
|
});
|
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("constraints a target to a limited range", check => {
|
2015-02-06 00:00:00 +00:00
|
|
|
var target = Target.newFromLocation(5, 9);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.equals(target.constraintInRange(1, 1, Math.sqrt(80) * 0.5), Target.newFromLocation(3, 5));
|
|
|
|
check.same(target.constraintInRange(1, 1, 70), target);
|
2015-02-06 00:00:00 +00:00
|
|
|
});
|
2015-04-21 20:14:17 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("pushes a target out of a given circle", check => {
|
2015-04-21 20:14:17 +00:00
|
|
|
var target = Target.newFromLocation(5, 5);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.same(target.moveOutOfCircle(0, 0, 3, 0, 0), target);
|
|
|
|
check.equals(target.moveOutOfCircle(6, 6, 3, 0, 0), Target.newFromLocation(3.8786796564403576, 3.8786796564403576));
|
|
|
|
check.equals(target.moveOutOfCircle(4, 4, 3, 10, 10), Target.newFromLocation(6.121320343559642, 6.121320343559642));
|
|
|
|
check.equals(target.moveOutOfCircle(5, 8, 6, 5, 0), Target.newFromLocation(5, 2));
|
|
|
|
check.equals(target.moveOutOfCircle(5, 2, 6, 5, 10), Target.newFromLocation(5, 8));
|
|
|
|
check.equals(target.moveOutOfCircle(8, 5, 6, 0, 5), Target.newFromLocation(2, 5));
|
|
|
|
check.equals(target.moveOutOfCircle(2, 5, 6, 10, 5), Target.newFromLocation(8, 5));
|
2015-04-21 20:14:17 +00:00
|
|
|
});
|
2017-05-29 20:39:07 +00:00
|
|
|
|
2017-10-26 21:47:13 +00:00
|
|
|
test.case("keeps a target inside a rectangle", check => {
|
2017-05-29 20:39:07 +00:00
|
|
|
var target = Target.newFromLocation(5, 5);
|
2017-10-26 21:47:13 +00:00
|
|
|
check.same(target.keepInsideRectangle(0, 0, 10, 10, 0, 0), target);
|
|
|
|
check.equals(target.keepInsideRectangle(8, 0, 13, 10, 10, 5), Target.newFromLocation(8, 5));
|
2017-05-29 20:39:07 +00:00
|
|
|
});
|
2015-02-06 00:00:00 +00:00
|
|
|
});
|
|
|
|
}
|