|
1 |
| -import { centerOf, randomPointIn } from "./location.function"; |
2 |
| -import { Point } from "./point.class"; |
3 |
| -import { Region } from "./region.class"; |
| 1 | +import {centerOf, randomPointIn} from "./location.function"; |
| 2 | +import {Point} from "./point.class"; |
| 3 | +import {Region} from "./region.class"; |
4 | 4 |
|
5 | 5 | describe("Location", () => {
|
6 |
| - it("should return the center point of an area.", () => { |
7 |
| - const expected = new Point(2, 2); |
8 |
| - const testRegion = new Region(0, 0, 4, 4); |
| 6 | + describe('centerOf', () => { |
| 7 | + it("should return the center point of an area.", () => { |
| 8 | + const expected = new Point(2, 2); |
| 9 | + const testRegion = new Region(0, 0, 4, 4); |
9 | 10 |
|
10 |
| - expect(centerOf(testRegion)).resolves.toEqual(expected); |
11 |
| - }); |
| 11 | + expect(centerOf(testRegion)).resolves.toEqual(expected); |
| 12 | + }); |
12 | 13 |
|
13 |
| - it("should return a random point inside of an area.", async () => { |
14 |
| - const testRegion = new Region(100, 20, 50, 35); |
15 |
| - const result = await randomPointIn(testRegion); |
16 |
| - expect(result.x).toBeGreaterThanOrEqual(testRegion.left); |
17 |
| - expect(result.x).toBeLessThanOrEqual(testRegion.left + testRegion.width); |
18 |
| - expect(result.y).toBeGreaterThanOrEqual(testRegion.top); |
19 |
| - expect(result.y).toBeLessThanOrEqual(testRegion.top + testRegion.height); |
20 |
| - }); |
| 14 | + it("should throw on non Region input", async () => { |
| 15 | + const testRegion = { |
| 16 | + left: 0, |
| 17 | + top: 0, |
| 18 | + width: 4 |
| 19 | + }; |
| 20 | + |
| 21 | + await expect(centerOf(testRegion as Region)).rejects.toThrowError(/^centerOf requires a Region, but received/); |
| 22 | + }); |
| 23 | + }); |
| 24 | + |
| 25 | + describe('randomPointIn', () => { |
| 26 | + it("should return a random point inside of an area.", async () => { |
| 27 | + const testRegion = new Region(100, 20, 50, 35); |
| 28 | + const result = await randomPointIn(testRegion); |
| 29 | + expect(result.x).toBeGreaterThanOrEqual(testRegion.left); |
| 30 | + expect(result.x).toBeLessThanOrEqual(testRegion.left + testRegion.width); |
| 31 | + expect(result.y).toBeGreaterThanOrEqual(testRegion.top); |
| 32 | + expect(result.y).toBeLessThanOrEqual(testRegion.top + testRegion.height); |
| 33 | + }); |
| 34 | + |
| 35 | + it("should throw on non Region input", async () => { |
| 36 | + const testRegion = { |
| 37 | + left: 0, |
| 38 | + top: 0, |
| 39 | + width: 4 |
| 40 | + }; |
| 41 | + |
| 42 | + await expect(randomPointIn(testRegion as Region)).rejects.toThrowError(/^randomPointIn requires a Region, but received/); |
| 43 | + }); |
| 44 | + }); |
21 | 45 | });
|
0 commit comments