From 320b9196c48631ac39c394273b6e7f4cc1291774 Mon Sep 17 00:00:00 2001 From: Ryan Reilly Date: Sun, 8 Oct 2023 13:52:26 -0400 Subject: [PATCH] Comprehensive Point tests w/test.each() Point.test.ts - test.each now compacts some otherwise repetitive testing committed AEGTree.ts - added author tags and changed documentation AtomNode.ts - changed documentation --- src/AEG/AEGTree.ts | 7 ++++++- src/AEG/AtomNode.ts | 2 +- tests/Point.test.ts | 35 ++++++++++++++++++++++++++--------- 3 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/AEG/AEGTree.ts b/src/AEG/AEGTree.ts index e4c8a431..35509d7c 100644 --- a/src/AEG/AEGTree.ts +++ b/src/AEG/AEGTree.ts @@ -3,6 +3,11 @@ import {CutNode} from "./CutNode"; import {Point} from "./Point"; import {Ellipse} from "./Ellipse"; +/** + * Represents the background AEG tree structure. + * @author Ryan Reilly + * @author Anusha Tiwari + */ export class AEGTree { sheet: CutNode; @@ -55,7 +60,7 @@ export class AEGTree { } /** - * Method that checks whether the given node can be inserted into this tree + * Checks whether the given node can be inserted into this tree * at a given point without overlapping any bounding boxes. * @param incomingNode The node to be inserted. * @returns True, if the node can be inserted. Else, false diff --git a/src/AEG/AtomNode.ts b/src/AEG/AtomNode.ts index 9db61c47..cf0e8d7d 100644 --- a/src/AEG/AtomNode.ts +++ b/src/AEG/AtomNode.ts @@ -4,7 +4,7 @@ import {Ellipse} from "./Ellipse"; import {Point} from "./Point"; /** - * Class that defines an Atom. + * Defines an Atom. * @author Anusha Tiwari * @author Ryan Reilly */ diff --git a/tests/Point.test.ts b/tests/Point.test.ts index 9364663e..7c2046a1 100644 --- a/tests/Point.test.ts +++ b/tests/Point.test.ts @@ -2,6 +2,11 @@ import {describe, expect, test} from "vitest"; import {Point} from "../src/AEG/Point"; +/** + * Details comprehensive unit tests on the Point class. + * @author Ryan Reilly + */ + const point = new Point(); const point2 = new Point(); @@ -9,11 +14,9 @@ describe("Point constructor series: ", () => { test("Default constructor should make a Point with X = 0.", () => { expect(point.x).toBe(0); }); - test("Default constructor should make a Point with Y = 0.", () => { expect(point.y).toBe(0); }); - test("Point.toString() should produce a string of the form (x, y).", () => { expect(point.toString()).toBe("(0, 0)"); }); @@ -23,11 +26,9 @@ describe("Point constructor series: ", () => { test("Two arg constructor [(Point(10, 10)] should make a Point with X = 10.", () => { expect(point2.x).toBe(10); }); - test("Two arg constructor [(Point(10, 10)] should make a Point with Y = 10.", () => { expect(point2.y).toBe(10); }); - test("Point.toString() should now produce a string of the form (x, y) with {x, y} = 10.", () => { expect(point2.toString()).toBe("(10, 10)"); }); @@ -45,12 +46,28 @@ describe("Point set series:", () => { }); }); -describe("Point distance series:", () => { - test("A Point's distance with itself should be 0.", () => { - expect(point.distance(point)).toBe(0); +describe("Point distance series (non float):", () => { + test.each([ + [point, point, 0], + [point, new Point(10, 10), Math.sqrt(200)], + [point, new Point(-10, 10), Math.sqrt(200)], + [point, new Point(-10, -10), Math.sqrt(200)], + [point, new Point(NaN, NaN), NaN], + [point, new Point(Infinity, Infinity), Infinity], + [point, new Point(-Infinity, Infinity), Infinity], + [point, new Point(-Infinity, -Infinity), Infinity], + ])("Distance between %o, %o, should be %i", (p1, p2, expected) => { + expect(p1.distance(p2)).toBe(expected); }); +}); - test("A Point (0, 0)'s distance with a Point (20, 20) should be sqrt(800)", () => { - expect(point.distance(point2)).toBe(Math.sqrt(800)); +describe("Point distance series (float):", () => { + test.each([ + [point, new Point(0.00000000000001, 0.000000000001), 0], + [point, new Point(-0.00000000001, -0.0000000000001), 0], + [point, new Point(-0.0000000000001, -0.0000000000001), 0], + [point, new Point(0.0000000000000000000000000000000000000000000001, 0.000000000000001), 0], + ])("Distance between %o, %o, should be nearly %i", (p1, p2, expected) => { + expect(p1.distance(p2)).toBeCloseTo(expected); }); });