Skip to content

Commit 2f6ae9e

Browse files
author
Calvin Metcalf
committed
tape
1 parent 8a86762 commit 2f6ae9e

File tree

7 files changed

+153
-237
lines changed

7 files changed

+153
-237
lines changed

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
"test": "test"
2020
},
2121
"scripts": {
22-
"test": "npm run build && jshint lib && mocha -R spec test/*.test.js",
22+
"test": "npm run build && jshint lib && tape spec test/*.test.js | tspec",
2323
"build": "npm run build-js && npm run min",
2424
"build-js": "browserify . > dist/rtree.js",
2525
"min": "uglifyjs ./dist/rtree.js > dist/rtree.min.js"
@@ -30,9 +30,9 @@
3030
},
3131
"devDependencies": {
3232
"browserify": "^3.41.0",
33-
"chai": "^1.9.1",
3433
"jshint": "^2.5.0",
35-
"mocha": "^1.18.2",
34+
"tap-spec": "^0.1.8",
35+
"tape": "^2.12.3",
3636
"uglify-js": "^2.4.13"
3737
}
3838
}

test/basic.test.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
1-
require('chai').should();
1+
var test = require('tape');
22
var data = require('./data');
33
var RTree = require('../lib');
4-
describe('RTree Creation', function() {
5-
var rt = new RTree();
6-
it('Insert 1k Objects', function() {
7-
data[0].forEach(function(v) {
8-
rt.insert(v[0], v[1]);
9-
});
10-
var rslt = rt.search({
11-
x: 0,
12-
y: 0,
13-
w: 10600,
14-
h: 10600
15-
});
16-
rslt.should.have.length(1000);
17-
});
18-
it('Insert 1k more Objects', function() {
19-
data[1].forEach(function(v) {
20-
rt.insert(v[0], v[1]);
21-
});
22-
rt.search({
23-
x: 0,
24-
y: 0,
25-
w: 10600,
26-
h: 10600
27-
}).should.have.length(2000);
28-
});
4+
test('RTree Creation', function(t) {
5+
var rt = new RTree();
6+
t.plan(2);
7+
data[0].forEach(function(v) {
8+
rt.insert(v[0], v[1]);
9+
});
10+
t.equals(rt.search({
11+
x: 0,
12+
y: 0,
13+
w: 10600,
14+
h: 10600
15+
}).length, 1000, 'Insert 1k Objects');
16+
data[1].forEach(function(v) {
17+
rt.insert(v[0], v[1]);
18+
});
19+
t.equals(rt.search({
20+
x: 0,
21+
y: 0,
22+
w: 10600,
23+
h: 10600
24+
}).length, 2000, 'Insert 1k more Objects');
2925
});

test/creation.test.js

Lines changed: 0 additions & 68 deletions
This file was deleted.

test/deletion.test.js

Lines changed: 63 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -1,75 +1,69 @@
1-
require('chai').should();
1+
var test = require('tape');
22
var data = require('./data');
33
var RTree = require('../lib');
4-
describe('RTree Deletion 1', function() {
5-
var rt = new RTree();
6-
data[0].forEach(function(v) {
7-
rt.insert(v[0], v[1]);
8-
});
9-
data[1].forEach(function(v) {
10-
rt.insert(v[0], v[1]);
11-
});
12-
var bounds = {
13-
x: 5000,
14-
y: 0,
15-
w: 5500,
16-
h: 10500
17-
};
18-
var expect = rt.search(bounds);
19-
var rslt = rt.remove(bounds).map(function(a) {
20-
return a.leaf;
21-
});
22-
it('same result as a search?', function() {
4+
test('RTree Deletion 1', function(t) {
5+
var rt = new RTree();
6+
data[0].forEach(function(v) {
7+
rt.insert(v[0], v[1]);
8+
});
9+
data[1].forEach(function(v) {
10+
rt.insert(v[0], v[1]);
11+
});
12+
var bounds = {
13+
x: 5000,
14+
y: 0,
15+
w: 5500,
16+
h: 10500
17+
};
18+
var expect = rt.search(bounds);
19+
var rslt = rt.remove(bounds).map(function(a) {
20+
return a.leaf;
21+
});
22+
t.plan(1);
2323

2424

25-
expect.forEach(function(a) {
26-
//console.log(a,rslt[0]);
27-
rslt.should.include(a);
28-
});
29-
});
30-
it('get them all?', function() {
31-
var rslt2 = rt.remove({
32-
x: 0,
33-
y: 0,
34-
w: 5000,
35-
h: 10500
36-
});
37-
(rslt2.length + rslt.length).should.equal(2000);
38-
});
25+
expect.forEach(function(a) {
26+
if(!~rslt.indexOf(a)) {
27+
t.fail('didn\'t include it');
28+
}
29+
});
30+
var rslt2 = rt.remove({
31+
x: 0,
32+
y: 0,
33+
w: 5000,
34+
h: 10500
35+
});
36+
t.equals((rslt2.length + rslt.length), 2000, 'got them all');
3937
});
40-
describe('RTree Deletion 2', function() {
41-
var rt = new RTree();
42-
data[1].forEach(function(v) {
43-
rt.insert(v[0], v[1]);
44-
});
45-
data[0].forEach(function(v) {
46-
rt.insert(v[0], v[1]);
47-
});
48-
var bounds = {
49-
x: 5000,
50-
y: 0,
51-
w: 5500,
52-
h: 10500
53-
};
54-
var expect = rt.search(bounds);
55-
var rslt = rt.remove(bounds).map(function(a) {
56-
return a.leaf;
57-
});
58-
it('same result as a search?', function() {
59-
60-
61-
expect.forEach(function(a) {
62-
//console.log(a,rslt[0]);
63-
rslt.should.include(a);
64-
});
65-
});
66-
it('get them all?', function() {
67-
var rslt2 = rt.remove({
68-
x: 0,
69-
y: 0,
70-
w: 5000,
71-
h: 10500
72-
});
73-
(rslt2.length + rslt.length).should.equal(2000);
74-
});
38+
test('RTree Deletion 2', function(t) {
39+
var rt = new RTree();
40+
data[1].forEach(function(v) {
41+
rt.insert(v[0], v[1]);
42+
});
43+
data[0].forEach(function(v) {
44+
rt.insert(v[0], v[1]);
45+
});
46+
var bounds = {
47+
x: 5000,
48+
y: 0,
49+
w: 5500,
50+
h: 10500
51+
};
52+
var expect = rt.search(bounds);
53+
var rslt = rt.remove(bounds).map(function(a) {
54+
return a.leaf;
55+
});
56+
t.plan(1);
57+
expect.forEach(function(a) {
58+
if(!~rslt.indexOf(a)) {
59+
t.fail('didn\'t include it');
60+
}
61+
});
62+
var rslt2 = rt.remove({
63+
x: 0,
64+
y: 0,
65+
w: 5000,
66+
h: 10500
67+
});
68+
t.equals((rslt2.length + rslt.length), 2000, 'got them all');
7569
});

test/geojson.test.js

Lines changed: 9 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

test/json.test.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,22 @@
1-
require('chai').should();
1+
var test = require('tape');
22
var data = require('./data');
33
var RTree = require('../lib');
4-
describe('JSON', function() {
5-
var rt = new RTree();
6-
data[1].forEach(function(v) {
7-
rt.insert(v[0], v[1]);
8-
});
9-
data[0].forEach(function(v) {
10-
rt.insert(v[0], v[1]);
11-
});
12-
var fromJson;
13-
it('should produce valid json', function() {
14-
fromJson = rt.toJSON();
15-
JSON.parse(fromJson);
16-
});
17-
it('should work the other way', function() {
18-
rt.getTree().should.deep.equal(RTree.fromJSON(fromJson).getTree());
19-
});
4+
test('JSON', function(t) {
5+
var rt = new RTree();
6+
data[1].forEach(function(v) {
7+
rt.insert(v[0], v[1]);
8+
});
9+
data[0].forEach(function(v) {
10+
rt.insert(v[0], v[1]);
11+
});
12+
var fromJson;
13+
t.plan(2);
14+
try {
15+
fromJson = rt.toJSON();
16+
JSON.parse(fromJson);
17+
t.pass('able to parse json');
18+
} catch (e) {
19+
t.fail('unable to parse json');
20+
}
21+
t.deepEqual(rt.getTree(), RTree.fromJSON(fromJson).getTree(), 'should work the other way');
2022
});

0 commit comments

Comments
 (0)