-
Notifications
You must be signed in to change notification settings - Fork 2
/
test.js
42 lines (37 loc) · 1.02 KB
/
test.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
var level = require('levelup')
var memdown = require('memdown')
var levelZ = require('./index.js')
var assert = require('assert')
var db = level('./db', {db: memdown})
var grid = levelZ(db, 'grid', {
keys: ['x', 'y']
})
var n = 0;
for (var i = -18; i <= 18; ++i) {
for (var j = -9; j <= 9; ++j) {
grid.put(n++, {
x: i * 10,
y: j * 10,
key: n,
value: i * j
})
}
}
var results = []
grid.inBoundingBox([[-10, 10], [10,-10]]).on('data', function (location) {
results.push(location)
}).on('end', function () {
assert.equal(results.length, 9)
assert.equal(JSON.stringify(results), JSON.stringify([
{ x: -10, y: -10, key: 332, value: 1 },
{ x: -10, y: 0, key: 333, value: 0 },
{ x: 0, y: -10, key: 351, value: 0 },
{ x: 0, y: 0, key: 352, value: 0 },
{ x: -10, y: 10, key: 334, value: -1 },
{ x: 10, y: -10, key: 370, value: -1 },
{ x: 10, y: 0, key: 371, value: 0 },
{ x: 0, y: 10, key: 353, value: 0 },
{ x: 10, y: 10, key: 372, value: 1 }
]))
console.log('ok')
})