Skip to content

Commit

Permalink
Comprehensive Point tests w/test.each()
Browse files Browse the repository at this point in the history
Point.test.ts - test.each now compacts some otherwise repetitive testing committed
AEGTree.ts - added author tags and changed documentation
AtomNode.ts - changed documentation
  • Loading branch information
RyanR712 committed Oct 8, 2023
1 parent 531d328 commit 320b919
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 11 deletions.
7 changes: 6 additions & 1 deletion src/AEG/AEGTree.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/AEG/AtomNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down
35 changes: 26 additions & 9 deletions tests/Point.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@ 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();

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)");
});
Expand All @@ -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)");
});
Expand All @@ -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);
});
});

0 comments on commit 320b919

Please sign in to comment.