diff --git a/README.md b/README.md index 3b0d9d8c..77176294 100644 --- a/README.md +++ b/README.md @@ -8,7 +8,7 @@ Sponsored by James Oswald (RAIR Lab) ## Development -**All listed commands should be run in the project root** +**All listed commands should be run in the project root (Peirce-My-Heart)** ### Documentation @@ -101,7 +101,7 @@ will be jumped to in VSC. ## Testing Test your changes! Vitest will help here by looking for all .test.ts files in /tests/ and running them. -To perform this locally in a terminal, run the following from THE ROOT DIRECTORY (Peirce-My-Heart): +To perform this locally in a terminal, run the following: ```bash npm run test ``` @@ -113,7 +113,7 @@ npm run test /src/ : source code for the application -/tests/ : vitest compatible .test.ts files that are run and must be passed before all pushes to main +/tests/ : vitest compatible .test.ts files that are run on commits and must be passed before all merges to master /.eslintignore : list of .js and .ts files the linter shouldn't look at @@ -121,6 +121,8 @@ npm run test /.gitignore : list of files and folders shouldn't be uploaded with git version control +/.npmignore : list of the files NPM shouldn't peep + /.prettierrc.js : config for prettier, which catches syntactic errors in your typescript code. /LICENSE : The legal jargon for who can use and sell the project. diff --git a/tests/Ellipse.test.ts b/tests/Ellipse.test.ts index 4e531f5a..889d3f05 100644 --- a/tests/Ellipse.test.ts +++ b/tests/Ellipse.test.ts @@ -100,8 +100,12 @@ describe("Ellipse-on-Rectangle overlaps soliloquy:", () => { ); }); -describe.skip("Ellipse-on-Ellipse overlaps soliloquy:", () => { +describe("Ellipse-on-Ellipse overlaps soliloquy:", () => { const ell: Ellipse = new Ellipse(new Point(5, 5), 5, 5); //diameters of 10 + + test("Any Ellipse should overlap an Ellipse with the same measurements.", () => { + expect(ell.overlaps(ell)).toBeTruthy(); + }); }); describe("Ellipse-on-Rectangle contains soliloquy:", () => { @@ -121,7 +125,7 @@ describe("Ellipse-on-Rectangle contains soliloquy:", () => { describe("Ellipse-on-Ellipse contains soliloquy:", () => { const ell: Ellipse = new Ellipse(new Point(5, 5), 5, 5); //diameters of 10 - test("An Ellipse of center (0, 0) and {radX, radY} = 5 should not contain an Ellipse with the same measurements.", () => { + test("Any Ellipse should not contain an Ellipse with the same measurements.", () => { expect(ell.contains(new Rectangle(new Point(0, 0), 5, 5))).toBeFalsy(); }); }); diff --git a/tests/Rectangle.test.ts b/tests/Rectangle.test.ts index f915d462..262c9d06 100644 --- a/tests/Rectangle.test.ts +++ b/tests/Rectangle.test.ts @@ -1,6 +1,7 @@ import {describe, expect, test} from "vitest"; import {Rectangle} from "../src/AEG/Rectangle"; +import {Ellipse} from "../src/AEG/Ellipse"; import {Point} from "../src/AEG/Point"; /** @@ -120,8 +121,45 @@ describe("Rectangle-on-Rectangle overlaps soliloquy:", () => { ); }); +//skipping until the code determining this is hammered out describe.skip("Rectangle-on-Ellipse overlaps soliloquy:", () => { const rect: Rectangle = new Rectangle(new Point(0, 0), 10, 10); + + //same logic with Rectangle's overlaps(), touching points along the edge should be overlap + //set to skip until Ellipse's overlaps, at least from a design choice perspective, are + //hammered out + test.skip.each([ + [15, 0, 5, 5], //Ellipse touching the top right vertex of this Rectangle + [-5, 0, 5, 5], //Ellipse touching the top left vertex of this Rectangle + [-5, 10, 5, 5], //Ellipse touching the bottom left vertex of this Rectangle + [15, 10, 5, 5], //Ellipse touching the bottom right vertex of this Rectangle + ])( + "Rectangle of TL vertex (0, 0) and {w, h} = 10 should overlap with Ellipse of center (%f, %f) and radX = %f, radY = %f.", + (x, y, radX, radY) => { + expect(rect.overlaps(new Ellipse(new Point(x, y), radX, radY))).toBeTruthy(); + } + ); + + //this block should be combined with the above block when design decisions are hammered out + test.skip.each([ + [5, 5, 20, 20], //begins inside the Rectangle but touches the Rectangle's bounds from inside + [-5, 0, 20, 20], //begins outside the Rectangle but touches the Rectangle's bounds from outside + ])( + "Rectangle of TL vertex (0, 0) and {w, h} = 10 should overlap with Ellipse of center (%f, %f) and radX = %f, radY = %f.", + (x, y, radX, radY) => { + expect(rect.overlaps(new Ellipse(new Point(x, y), radX, radY))).toBeTruthy(); + } + ); + + test.each([ + [5, 5, 1, 1], //tiny guy + [5, 5, 20, 20], //huge guy + ])( + "Ellipse of center (5, 5) and {radX, radY} = 5 should not overlap with Rectangle of TL vertex (%f, %f) and w = %f, h = %f.", + (x, y, radX, radY) => { + expect(rect.overlaps(new Rectangle(new Point(x, y), radX, radY))).toBeFalsy(); + } + ); }); describe("Rectangle-on-Rectangle contains soliloquy:", () => { @@ -158,8 +196,46 @@ describe("Rectangle-on-Rectangle contains soliloquy:", () => { ); }); -describe.skip("Rectangle-on-Ellipse contains soliloquy:", () => { +describe("Rectangle-on-Ellipse contains soliloquy:", () => { const rect: Rectangle = new Rectangle(new Point(0, 0), 10, 10); + + test.each([ + [0, 0, 5, 5], //should not contain Ellipses whose centers are on corners or edges + [10, 0, 5, 5], + [0, 10, 5, 5], + [10, 10, 5, 5], + [0, 5, 5, 5], + [5, 0, 5, 5], + [10, 5, 5, 5], + [5, 10, 5, 5], + //should not contain Ellipses whose farthest points touch corners or edges + [15, 10, 5, 5], //touches (10, 10) on the Rectangle + [15, 5, 5, 5], //touches (10, 5) on the Rectangle + [15, 0, 5, 5], //touches (10, 0) on the Rectangle + [5, -5, 5, 5], //touches (5, 0) on the Rectangle + [-5, 0, 5, 5], //touches (0, 0) on the Rectangle + [-5, 5, 5, 5], //touches (0, 5) on the Rectangle + [-5, 10, 5, 5], //touches (0, 10) on the Rectangle + [5, 15, 5, 5], //touches (5, 10) on the Rectangle + ])( + "Rectangle of TL vertex (0, 0) and {w, h} = 10 should not contain Ellipse of center (%f, %f) and radX = %f, radY = %f.", + (x, y, rx, ry) => { + expect(rect.contains(new Ellipse(new Point(x, y), rx, ry))).toBeFalsy(); + } + ); + + test.each([ + [5, 5, 2, 2], //arbitrary Ellipses that should be contained within the Rectangle + [9.9, 9.9, 0, 0], + [0.1, 0.1, 0.01, 0.01], + [9.9, 0.1, 0.001, 0.001], + [0.1, 9.9, 0.0001, 0.0001], + ])( + "Rectangle of TL vertex (0, 0) and {w, h} = 10 should not contain Ellipse of center (%f, %f) and radX = %f, radY = %f.", + (x, y, rx, ry) => { + expect(rect.contains(new Ellipse(new Point(x, y), rx, ry))).toBeTruthy(); + } + ); }); describe("Rectangle toString soliloquy:", () => {