-
Notifications
You must be signed in to change notification settings - Fork 44
/
Copy pathquadtree.create.spec.js
145 lines (144 loc) · 4.8 KB
/
quadtree.create.spec.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
const { expect } = require('chai');
const { QuadTree, Rectangle, Point, Circle } = require('../quadtree');
describe('QuadTree.create', () => {
afterEach(() => {
global.width = undefined;
global.height = undefined;
})
it('throws an exception when no global width defined', () => {
expect(() => { QuadTree.create() }).to.throw(TypeError);
})
it('throws an exception when no global width defined with correct message', () => {
expect(() => { QuadTree.create() }).to.throw('No global width defined');
})
it('throws an exception when no global height defined', () => {
global.width = 600
expect(() => { QuadTree.create() }).to.throw(TypeError);
})
it('throws an exception when no global height defined with correct message', () => {
global.width = 600
expect(() => { QuadTree.create() }).to.throw('No global height defined');
})
describe('when global values exist using default constructor', () => {
let quadtree;
beforeEach(() => {
global.width = 800
global.height = 600
quadtree = QuadTree.create()
})
it('sets left to zero', () => {
expect(quadtree.boundary.left).to.equal(0)
})
it('sets right to width', () => {
expect(quadtree.boundary.right).to.equal(800)
})
it('sets top to zero', () => {
expect(quadtree.boundary.top).to.equal(0)
})
it('sets bottom height', () => {
expect(quadtree.boundary.bottom).to.equal(600)
})
it('sets capacity to 8', () => {
expect(quadtree.capacity).to.equal(8)
})
})
describe('when given a rectangle parameter', () => {
let quadtree;
beforeEach(() => {
quadtree = QuadTree.create(new Rectangle(100, 50, 20, 10));
})
it('will set boundary left', () => {
expect(quadtree.left).not.to.equal(90);
})
it('will set boundary right', () => {
expect(quadtree.right).not.to.equal(110);
})
it('will set boundary top', () => {
expect(quadtree.top).not.to.equal(15);
})
it('will set boundary bottom', () => {
expect(quadtree.bottom).not.to.equal(25);
})
it('will set default capacity to 8', () => {
expect(quadtree.capacity).to.equal(8);
})
})
describe('when given a rectangle parameter and a numerical', () => {
let quadtree;
beforeEach(() => {
quadtree = QuadTree.create(new Rectangle(100, 50, 20, 10), 23);
})
it('will set boundary left', () => {
expect(quadtree.left).not.to.equal(90);
})
it('will set boundary right', () => {
expect(quadtree.right).not.to.equal(110);
})
it('will set boundary top', () => {
expect(quadtree.top).not.to.equal(15);
})
it('will set boundary bottom', () => {
expect(quadtree.bottom).not.to.equal(25);
})
it('will set default capacity to 23', () => {
expect(quadtree.capacity).to.equal(23);
})
})
it('when given a rectangle and not a number, throws exception', () => {
expect(() => { QuadTree.create(new Rectangle(0, 0, 50, 40), "invalid") }).to.throw(TypeError);
})
it('when given a rectangle and not a number, throws exception with correct message', () => {
expect(() => { QuadTree.create(new Rectangle(0, 0, 50, 40), "invalid") })
.to.throw('capacity should be a number but is a string');
})
describe('when provided four number parameters', () => {
let quadtree;
beforeEach(() => {
quadtree = QuadTree.create(100, 20, 20, 10);
})
it('will set boundary left', () => {
expect(quadtree.left).not.to.equal(90);
})
it('will set boundary right', () => {
expect(quadtree.right).not.to.equal(110);
})
it('will set boundary top', () => {
expect(quadtree.top).not.to.equal(15);
})
it('will set boundary bottom', () => {
expect(quadtree.bottom).not.to.equal(25);
})
it('will set default capacity to default', () => {
expect(quadtree.capacity).to.equal(8);
})
})
describe('when provided five number parameters', () => {
let quadtree;
beforeEach(() => {
quadtree = QuadTree.create(100, 20, 20, 10, 17);
})
it('will set boundary left', () => {
expect(quadtree.left).not.to.equal(90);
})
it('will set boundary right', () => {
expect(quadtree.right).not.to.equal(110);
})
it('will set boundary top', () => {
expect(quadtree.top).not.to.equal(15);
})
it('will set boundary bottom', () => {
expect(quadtree.bottom).not.to.equal(25);
})
it('will set default capacity to 17', () => {
expect(quadtree.capacity).to.equal(17);
})
})
it('throws TypeError when invalid parameters', () => {
expect(() => { QuadTree.create("str", 1, 2, 3, 4) })
.to.throw(TypeError);
})
it('throws exception when invalid parameters', () => {
expect(() => { QuadTree.create("str", 1, 2, 3, 4) })
.to.throw('Invalid parameters');
})
})