Skip to content

Commit

Permalink
feat: all collision unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
RoxaneBurri committed Mar 14, 2023
1 parent 6041b97 commit 755b8f2
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion src/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest";
import {
areCentersTooClose,
Coordinate,
getBoundingRect,
allCollision,
Rectangle,
getMoveDirection,
} from "./utils";
Expand All @@ -12,6 +12,13 @@ const origin: Coordinate = {
y: 0,
};

const originRectangle: Rectangle = {
x: 0,
y: 0,
width: 1,
height: 1,
};

describe("areCentersTooClose", () => {
it("No collisions", () => {
expect(areCentersTooClose(origin, { x: 6, y: 0 }, 2, 2)).toBe(false);
Expand Down Expand Up @@ -90,3 +97,33 @@ describe("Get move direction", () => {
});
});
});

describe("All collision", () => {
it("True", () => {
expect(allCollision(originRectangle, [originRectangle])).toBe(true);
});

it("False", () => {
expect(
allCollision(originRectangle, [{ x: 4, y: 4, width: 2, height: 2 }])
).toBe(false);
});

it("Two placed element true", () => {
expect(
allCollision(originRectangle, [
{ x: 2, y: 2, width: 4, height: 4 },
{ x: 6, y: 6, width: 2, height: 2 },
])
).toBe(true);
});

it("Two placed element false", () => {
expect(
allCollision(originRectangle, [
{ x: 2, y: 2, width: 4, height: 4 },
{ x: 6, y: 6, width: 2, height: 2 },
])
).toBe(true);
});
});

0 comments on commit 755b8f2

Please sign in to comment.