Skip to content

Commit 75e7b2e

Browse files
author
Chris Hallberg
committed
Add more tests for closest.
1 parent a11fa93 commit 75e7b2e

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

test/quadtree.spec.js

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,15 +318,26 @@ describe('QuadTree', () => {
318318
];
319319
points.forEach(point => quadtree.insert(point));
320320
});
321+
it('requires a point to query', () => {
322+
expect(() => { quadtree.closest() }).to.throw("Method 'closest' needs a point");
323+
});
321324
it('returns empty array when quadtree is empty', () => {
322325
quadtree = new QuadTree(new Rectangle(0, 0, 100, 100), 4);
323326
found = quadtree.closest(new Point(0, 0), 1);
324327
expect(found).to.have.length(0);
325328
});
329+
it('returns all items when number requested exceeds QuadTree contents', () => {
330+
found = quadtree.closest(new Point(0, 0), 10);
331+
expect(found).to.have.length(4);
332+
});
326333
it('returns closest item', () => {
327334
found = quadtree.closest(new Point(0, 0), 1);
328335
expect(found).to.contain(points[0]);
329336
});
337+
it('returns default number of items (one)', () => {
338+
found = quadtree.closest(new Point(0, 0));
339+
expect(found).to.have.length(1);
340+
});
330341
it('returns correct number of items (one)', () => {
331342
found = quadtree.closest(new Point(0, 0), 1);
332343
expect(found).to.have.length(1);
@@ -344,10 +355,6 @@ describe('QuadTree', () => {
344355
expect(found).to.have.length(1);
345356
expect(found).to.contain(points[0]);
346357
});
347-
it('returns all items when number requested exceeds QuadTree contents', () => {
348-
found = quadtree.closest(new Point(0, 0), 10);
349-
expect(found).to.have.length(4);
350-
});
351358
});
352359
describe('size', () => {
353360
let quadtree;

0 commit comments

Comments
 (0)