Add test cases for when the closest ships are on the edge

This commit is contained in:
Oliver Akins 2022-06-29 22:21:42 -06:00
parent 08df4187fb
commit 32119625b7
No known key found for this signature in database
GPG key ID: 3C2014AF9457AF99

View file

@ -108,6 +108,18 @@ describe("The determineDirection function", () => {
expect(determineDirection(b, p)).to.be.lessThan(0); expect(determineDirection(b, p)).to.be.lessThan(0);
}); });
it("should return negative when the closest ship is on the 0th index", () => {
let b = [ "p2", null, "p1", null, null, "p3", null ];
let p = b.findIndex(x => x == "p1");
expect(determineDirection(b, p)).to.be.lessThan(0);
});
it("should return negative when the closest ship is on the highest index", () => {
let b = [ null, "p2", null, null, "p1", null, "p3" ];
let p = b.findIndex(x => x == "p1");
expect(determineDirection(b, p)).to.be.greaterThan(0);
});
it("should return positive when the only other ship is at a higher index", () => { it("should return positive when the only other ship is at a higher index", () => {
let b = [ let b = [
null, null, null, null, null, null, null, null, null, null,