Add tests for the movementDirection function
This commit is contained in:
parent
4feafba99b
commit
3b78f224df
1 changed files with 135 additions and 1 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { countShips } from "./movementDirection"
|
||||
import { countShips, determineDirection } from "./movementDirection"
|
||||
import { expect } from "chai";
|
||||
import "mocha";
|
||||
|
||||
|
|
@ -44,4 +44,138 @@ describe("The countShips function", () => {
|
|||
throw "Function didn't throw an error";
|
||||
} catch (_) {}
|
||||
});
|
||||
});
|
||||
|
||||
describe("The movementDirection function", () => {
|
||||
|
||||
it("should return positive when no other ships present (0-index)", () => {
|
||||
let b = [
|
||||
"p1", null, null, null, null,
|
||||
null, null, null, null, null,
|
||||
null, null, null, null, null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it("should return positive when no other ships present (low-index)", () => {
|
||||
let b = [
|
||||
null, null, "p1", null, null,
|
||||
null, null, null, null, null,
|
||||
null, null, null, null, null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it("should return positive when no other ships present (mid-index)", () => {
|
||||
let b = [
|
||||
null, null, null, null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, null, null, null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it("should return positive when no other ships present (high-index)", () => {
|
||||
let b = [
|
||||
null, null, null, null, null,
|
||||
null, null, null, null, null,
|
||||
null, null, "p1", null, null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it("should return positive when no other ships present (max-index)", () => {
|
||||
let b = [
|
||||
null, null, null, null, null,
|
||||
null, null, null, null, null,
|
||||
null, null, null, null, "p1",
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it("should return negative when the only other ship is at a lower index", () => {
|
||||
let b = [
|
||||
null, "p2", null, null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, null, null, null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.lessThan(0);
|
||||
});
|
||||
|
||||
it("should return positive when the only other ship is at a higher index", () => {
|
||||
let b = [
|
||||
null, null, null, null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, null, "p2", null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
|
||||
it("should return positive when the closest ship is at a higher index", () => {
|
||||
let b = [
|
||||
null, "p3", null, null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, "p2", null, null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it("should return negative when the closest ship is at a lower index", () => {
|
||||
let b = [
|
||||
null, null, "p3", null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, null, "p2", null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.lessThan(0);
|
||||
});
|
||||
|
||||
it("should return 0 when there is a tie between the closest ships (no extra ships)", () => {
|
||||
let b = [
|
||||
null, null, "p3", null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, "p2", null, null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.equal(0);
|
||||
});
|
||||
|
||||
it("should return negative when there is a tie between the closest ships (extra ships in negative direction)", () => {
|
||||
let b = [
|
||||
null, "p4", "p3", null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, "p2", null, null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.lessThan(0);
|
||||
});
|
||||
|
||||
it("should return positive when there is a tie between the closest ships (extra ships in positive direction)", () => {
|
||||
let b = [
|
||||
null, null, "p3", null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, "p2", "p4", null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.be.greaterThan(0);
|
||||
});
|
||||
|
||||
it("should return positive when there is a tie between the closest ships (extra ships tied)", () => {
|
||||
let b = [
|
||||
null, "p5", "p3", null, null,
|
||||
null, null, "p1", null, null,
|
||||
null, null, "p2", "p4", null,
|
||||
];
|
||||
let p = b.findIndex(x => x == "p1");
|
||||
expect(determineDirection(b, p)).to.equal(0);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue