Skip to content

Commit

Permalink
What's that?? MORE comprehensive tests?!
Browse files Browse the repository at this point in the history
README.md - changed some excessive wording, added .npmignore to the source file explanation chunk
Rectangle.test.ts, Ellipse.test.ts - expanded on existing tests
  • Loading branch information
RyanR712 committed Oct 10, 2023
1 parent 30c6642 commit d20dc09
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 6 deletions.
8 changes: 5 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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
```
Expand All @@ -113,14 +113,16 @@ 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
/.eslintrc.json : config for the linter, which catches semantic errors in your typescript code.
/.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.
Expand Down
8 changes: 6 additions & 2 deletions tests/Ellipse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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:", () => {
Expand All @@ -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();
});
});
Expand Down
78 changes: 77 additions & 1 deletion tests/Rectangle.test.ts
Original file line number Diff line number Diff line change
@@ -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";

/**
Expand Down Expand Up @@ -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:", () => {
Expand Down Expand Up @@ -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:", () => {
Expand Down

0 comments on commit d20dc09

Please sign in to comment.