From 755b8f2f9baeb534fea35e7f2cfe696457906b67 Mon Sep 17 00:00:00 2001 From: RoxaneBurri Date: Tue, 14 Mar 2023 09:56:16 +0100 Subject: [PATCH] feat: all collision unit test --- src/utils.test.ts | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/src/utils.test.ts b/src/utils.test.ts index f566a4f..9b24d46 100644 --- a/src/utils.test.ts +++ b/src/utils.test.ts @@ -2,7 +2,7 @@ import { describe, expect, it } from "vitest"; import { areCentersTooClose, Coordinate, - getBoundingRect, + allCollision, Rectangle, getMoveDirection, } from "./utils"; @@ -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); @@ -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); + }); +});