-
Notifications
You must be signed in to change notification settings - Fork 1
/
test.js
37 lines (32 loc) · 1.23 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
const test = require('tape');
const path = require('path');
const glob = require('glob');
const load = require('load-json-file');
const write = require('write-json-file');
const truncate = require('@turf/truncate');
const circle = require('@turf/circle');
const matrixToGrid = require('./');
test('matrix-to-grid', t => {
glob.sync(path.join(__dirname, 'test', 'in', '*.json')).forEach(filepath => {
// Fixtures
const {name, dir} = path.parse(filepath);
const out = dir.replace(path.join('test', 'in'), path.join('test', 'out'));
const {matrix, origin, cellSize, options} = load.sync(filepath);
// Calculate results
let results = matrixToGrid(matrix, origin, cellSize, options);
// Add circle to results
results.features.push(circle(origin, cellSize / 15, {
steps: 20,
units: options.units,
properties: {
stroke: '#F00',
'stroke-width': 4
}
}));
results = truncate(results);
// Save results
if (process.env.REGEN) write.sync(path.join(out, name + '.geojson'), results);
t.deepEquals(results, load.sync(path.join(out, name + '.geojson')), name);
});
t.end();
});