Skip to content

Commit 6918d87

Browse files
committed
add tests for isWithinRect
1 parent ac26902 commit 6918d87

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import { expect } from '@open-wc/testing';
2+
import { isWithinRect } from './math.js';
3+
4+
describe('isWithinRect', () => {
5+
const rect = new DOMRect(0, 0, 100, 100);
6+
7+
it('should return true if the point is within the rectangle', () => {
8+
expect(isWithinRect(50, 50, rect)).to.be.true;
9+
expect(isWithinRect(1, 1, rect)).to.be.true;
10+
expect(isWithinRect(99, 99, rect)).to.be.true;
11+
});
12+
13+
it('should return false if the point is outside the rectangle', () => {
14+
expect(isWithinRect(0, 0, rect)).to.be.false;
15+
expect(isWithinRect(100, 100, rect)).to.be.false;
16+
expect(isWithinRect(101, 50, rect)).to.be.false;
17+
expect(isWithinRect(50, 101, rect)).to.be.false;
18+
expect(isWithinRect(-1, 50, rect)).to.be.false;
19+
expect(isWithinRect(50, -1, rect)).to.be.false;
20+
});
21+
22+
it('should return false if the point is on the "border" of the rectangle', () => {
23+
expect(isWithinRect(0, 0, rect)).to.be.false;
24+
expect(isWithinRect(100, 100, rect)).to.be.false;
25+
expect(isWithinRect(100, 0, rect)).to.be.false;
26+
expect(isWithinRect(0, 100, rect)).to.be.false;
27+
});
28+
29+
it('should return true if the point is within the expanded rectangle', () => {
30+
expect(isWithinRect(110, 80, rect, 20)).to.be.true;
31+
expect(isWithinRect(80, 110, rect, 20)).to.be.true;
32+
});
33+
34+
it('should return false if the point is outside the expanded rectangle', () => {
35+
expect(isWithinRect(130, 80, rect, 20)).to.be.false;
36+
expect(isWithinRect(80, 130, rect, 20)).to.be.false;
37+
});
38+
});

0 commit comments

Comments
 (0)