From 32119625b743f879ed3465c4ceebe83c10ec1919 Mon Sep 17 00:00:00 2001 From: Oliver Akins Date: Wed, 29 Jun 2022 22:21:42 -0600 Subject: [PATCH] Add test cases for when the closest ships are on the edge --- common/src/algorithms/movementDirection.spec.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/common/src/algorithms/movementDirection.spec.ts b/common/src/algorithms/movementDirection.spec.ts index 2376476..13d5aa2 100644 --- a/common/src/algorithms/movementDirection.spec.ts +++ b/common/src/algorithms/movementDirection.spec.ts @@ -108,6 +108,18 @@ describe("The determineDirection function", () => { 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", () => { let b = [ null, null, null, null, null,