Skip to content

Commit

Permalink
test: update test cases to work with old+new software versions
Browse files Browse the repository at this point in the history
  • Loading branch information
missinglink authored and orangejulius committed Jul 4, 2023
1 parent a1451e9 commit 3c4d6d3
Show file tree
Hide file tree
Showing 22 changed files with 152 additions and 136 deletions.
7 changes: 6 additions & 1 deletion test/_func.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@

var tape = require('tape');
var common = {};

var common = {
// fuzzy rewrites SQL table dumps to reduce floating point precision to max 8
truncate: (s) => s.match(/^-?[0-9]+\.[0-9]+$/) ? s.split('.').map(c => c.substring(0, 8)).join('.') : s,
fuzzy: (row) => row.split('|').map(common.truncate).join('|'),
};

var tests = [
require('./functional/basic/run.js'),
Expand Down
27 changes: 19 additions & 8 deletions test/functional/action.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,13 @@ var exec = {
vertices: path.resolve( __dirname, '../../cmd/vertices.js' )
};

// handle non-zero status code errors from shell commands
var must = (res) => {
if (res.status === 0) { return; }
console.error(res.stderr.toString());
process.exit(res.status);
};

// clean working directory
module.exports.clean = function(test, paths) {
test('clean', function(t) {
Expand All @@ -25,7 +32,7 @@ module.exports.clean = function(test, paths) {
].join(' ');

// spawn child process
child.spawnSync( 'sh', [ '-c', cmd ] );
must( child.spawnSync( 'sh', [ '-c', cmd ] ) );

t.pass('perform clean');
t.end();
Expand All @@ -44,7 +51,7 @@ module.exports.import = function(test, paths) {
].join(' ');

// spawn child process
child.spawnSync( 'sh', [ '-c', cmd ] );
must( child.spawnSync( 'sh', [ '-c', cmd ] ) );

t.pass('perform import');
t.end();
Expand All @@ -64,7 +71,7 @@ module.exports.oa = function(test, paths) {
].join(' ');

// spawn child process
child.spawnSync( 'sh', [ '-c', cmd ] );
must( child.spawnSync( 'sh', [ '-c', cmd ] ) );

t.pass('perform oa conflate');
t.end();
Expand All @@ -84,7 +91,7 @@ module.exports.osm = function(test, paths) {
].join(' ');

// spawn child process
child.spawnSync( 'sh', [ '-c', cmd ] );
must( child.spawnSync( 'sh', [ '-c', cmd ] ) );

t.pass('perform osm conflate');
t.end();
Expand All @@ -96,14 +103,14 @@ module.exports.tiger = function(test, paths) {

// conflate openstreetmap addresses
var cmd = [
'ogr2ogr -f GeoJSON -lco \'COORDINATE_PRECISION=7\' -t_srs crs:84 /vsistdout/', paths.fixture.tiger, '|',
'ogr2ogr -f GeoJSON -lco \'COORDINATE_PRECISION=7\' /vsistdout/', paths.fixture.tiger, '|',
'node', exec.tiger, paths.db.address, paths.db.street,
'1>', path.resolve( paths.reports, 'tiger.out' ),
'2>', path.resolve( paths.reports, 'tiger.err' )
].join(' ');

// spawn child process
child.spawnSync( 'sh', [ '-c', cmd ] );
must( child.spawnSync( 'sh', [ '-c', cmd ] ) );

t.pass('perform tiger conflate');
t.end();
Expand All @@ -121,7 +128,7 @@ module.exports.vertices = function(test, paths) {
].join(' ');

// spawn child process
child.spawnSync( 'sh', [ '-c', cmd ] );
must( child.spawnSync( 'sh', [ '-c', cmd ] ) );

t.pass('perform vertex interpolation');
t.end();
Expand All @@ -148,9 +155,13 @@ module.exports.check.schema = function(test, paths) {
'2|name|TEXT|0||0'
], 'table_info(names)');

// some versions of sqlite return the type 'NUM' for rtree columns while others do not.
// this method removes the type information so the tests are consistent between versions.
const rmtype = (row) => row.split('|').map((v, i) => i === 2 ? '' : v).join('|');

// rtree schema
var rtree = sqlite3.exec( paths.db.street, 'PRAGMA table_info(rtree)' );
t.deepEqual(rtree, [
t.deepEqual(rtree.map(rmtype), [
'0|id||0||0',
'1|minX||0||0',
'2|maxX||0||0',
Expand Down
4 changes: 2 additions & 2 deletions test/functional/ambiguous_street_name/reports/preview.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@
"lat": 52.5082458,
"lon": 13.3943829,
"parity": "L",
"proj_lat": 52.508231931767,
"proj_lat": 52.5082319317669,
"proj_lon": 13.3941549504635,
"marker-color": "#3366ff",
"marker-symbol": "e"
Expand Down Expand Up @@ -1558,7 +1558,7 @@
],
[
13.3941549504635,
52.508231931767
52.5082319317669
]
]
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/ambiguous_street_name/reports/preview.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ rowid id source source_id housenumber lat lon parity proj_lat proj_lon
40 4 OA 5b3d7b07fbfdc912 20.0 52.5076177 13.3944541 L 52.5076052737287 13.3942607247242
236 4 VERTEX 21.288 52.507915 13.394207
1 4 OA f3f06058e51114b1 22.0 52.5080983 13.3943789 L 52.5080861318112 13.3941788951131
2 4 OA 7b1ad3b0a9c833a6 22.03 52.5082458 13.3943829 L 52.508231931767 13.3941549504635
2 4 OA 7b1ad3b0a9c833a6 22.03 52.5082458 13.3943829 L 52.5082319317669 13.3941549504635
3 4 OA 673d5da459f98abe 23.0 52.508326 13.3943346 L 52.5083142478692 13.3941414317335
4 4 OA 1bd601d138c302b6 24.0 52.5084591 13.3943202 L 52.5084468986383 13.3941196465678
5 4 OA 847e15557713530c 25.0 52.5086293 13.3942947 L 52.5086169510415 13.3940917189516
Expand Down
10 changes: 5 additions & 5 deletions test/functional/ambiguous_street_name/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,16 +125,16 @@ module.exports.functional.spotcheck = function(test) {
});
};

module.exports.functional.end_to_end = function(test) {
module.exports.functional.end_to_end = function(test, { fuzzy }) {
test('end to end', function(t) {

// full interpolation for a single street
var rows = sqlite3.exec( paths.db.address, 'SELECT * FROM address WHERE id=1 ORDER BY housenumber' );
t.deepEqual(rows, fs.readFileSync( paths.expected1 ).toString('utf8').trim().split('\n') );
t.deepEqual(rows.map(fuzzy), fs.readFileSync( paths.expected1 ).toString('utf8').trim().split('\n').map(fuzzy) );

// full interpolation for a single street
rows = sqlite3.exec( paths.db.address, 'SELECT * FROM address WHERE id=4 ORDER BY housenumber' );
t.deepEqual(rows, fs.readFileSync( paths.expected2 ).toString('utf8').trim().split('\n') );
t.deepEqual(rows.map(fuzzy), fs.readFileSync( paths.expected2 ).toString('utf8').trim().split('\n').map(fuzzy) );

t.end();
});
Expand Down Expand Up @@ -228,13 +228,13 @@ module.exports.functional.tsv = function(test) {
action.tsv(test, paths, 'id=4');
};

module.exports.all = function (tape) {
module.exports.all = function (tape, common) {

function test(name, testFunction) {
return tape('functional: ambiguous_street_name: ' + name, testFunction);
}

for( var testCase in module.exports.functional ){
module.exports.functional[testCase](test);
module.exports.functional[testCase](test, common);
}
};
4 changes: 2 additions & 2 deletions test/functional/basic/reports/preview.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -384,7 +384,7 @@
"lat": -41.2888927,
"lon": 174.7667798,
"parity": "L",
"proj_lat": -41.28882860466,
"proj_lat": -41.2888286046601,
"proj_lon": 174.767113052137,
"marker-color": "#3366ff",
"marker-symbol": "e"
Expand Down Expand Up @@ -662,7 +662,7 @@
],
[
174.767113052137,
-41.28882860466
-41.2888286046601
]
]
}
Expand Down
2 changes: 1 addition & 1 deletion test/functional/basic/reports/preview.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ rowid id source source_id housenumber lat lon parity proj_lat proj_lon
15 1 VERTEX 16.194 -41.288659 174.767089
14 1 VERTEX 17.161 -41.288712 174.767089
4 1 OA cfb26db2d9d2f1a8 18.0 -41.2887878 174.7668435 L -41.288758 174.767089
6 1 OA 167efd93a1849abd 20.0 -41.2888927 174.7667798 L -41.28882860466 174.767113052137
6 1 OA 167efd93a1849abd 20.0 -41.2888927 174.7667798 L -41.2888286046601 174.767113052137
7 1 OA 4edfa83b89b96c5e 22.0 -41.2889696 174.7667528 L -41.288849 174.76712
13 1 VERTEX 22.772 -41.288914 174.767166
8 1 OA 09af01b0dd072957 24.0 -41.2890752 174.7671263 L -41.2890111515318 174.767252991894
Expand Down
8 changes: 4 additions & 4 deletions test/functional/basic/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ module.exports.functional.spotcheck = function(test) {
});
};

module.exports.functional.end_to_end = function(test) {
module.exports.functional.end_to_end = function(test, { fuzzy }) {
test('end to end', function(t) {

// full interpolation for a single street
var rows = sqlite3.exec( paths.db.address, 'SELECT * FROM address WHERE id=1 ORDER BY housenumber' );
t.deepEqual(rows, fs.readFileSync( paths.expected ).toString('utf8').trim().split('\n') );
t.deepEqual(rows.map(fuzzy), fs.readFileSync( paths.expected ).toString('utf8').trim().split('\n').map(fuzzy) );

t.end();
});
Expand Down Expand Up @@ -198,13 +198,13 @@ module.exports.functional.tsv = function(test) {
action.tsv(test, paths, 'id=1');
};

module.exports.all = function (tape) {
module.exports.all = function (tape, common) {

function test(name, testFunction) {
return tape('functional: basic: ' + name, testFunction);
}

for( var testCase in module.exports.functional ){
module.exports.functional[testCase](test);
module.exports.functional[testCase](test, common);
}
};
8 changes: 4 additions & 4 deletions test/functional/lueppold_rd/reports/preview.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@
"lat": 46.53376,
"lon": -110.94752,
"parity": "R",
"proj_lat": 46.5337752241147,
"proj_lat": 46.5337752241148,
"proj_lon": -110.947520259902,
"marker-color": "#ff0000",
"marker-symbol": "e"
Expand All @@ -384,7 +384,7 @@
"lat": 46.53376,
"lon": -110.94752,
"parity": "R",
"proj_lat": 46.5337752241147,
"proj_lat": 46.5337752241148,
"proj_lon": -110.947520259902,
"marker-color": "#ff0000",
"marker-symbol": "o"
Expand Down Expand Up @@ -612,7 +612,7 @@
],
[
-110.947520259902,
46.5337752241147
46.5337752241148
]
]
}
Expand All @@ -632,7 +632,7 @@
],
[
-110.947520259902,
46.5337752241147
46.5337752241148
]
]
}
Expand Down
4 changes: 2 additions & 2 deletions test/functional/lueppold_rd/reports/preview.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,5 @@ rowid id source source_id housenumber lat lon parity proj_lat proj_lon
16 1 VERTEX 116.503 46.53392 -110.926568
14 1 VERTEX 157.868 46.533863 -110.937203
13 1 VERTEX 161.517 46.533851 -110.938141
7 1 TIGER 263702490 198.0 46.53376 -110.94752 R 46.5337752241147 -110.947520259902
8 1 TIGER 208773717 199.0 46.53376 -110.94752 R 46.5337752241147 -110.947520259902
7 1 TIGER 263702490 198.0 46.53376 -110.94752 R 46.5337752241148 -110.947520259902
8 1 TIGER 208773717 199.0 46.53376 -110.94752 R 46.5337752241148 -110.947520259902
8 changes: 4 additions & 4 deletions test/functional/lueppold_rd/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,12 +98,12 @@ module.exports.functional.spotcheck = function(test) {
});
};

module.exports.functional.end_to_end = function(test) {
module.exports.functional.end_to_end = function(test, { fuzzy }) {
test('end to end', function(t) {

// full interpolation for a single street
var rows = sqlite3.exec( paths.db.address, 'SELECT * FROM address WHERE id=1 ORDER BY housenumber' );
t.deepEqual(rows, fs.readFileSync( paths.expected ).toString('utf8').trim().split('\n') );
t.deepEqual(rows.map(fuzzy), fs.readFileSync( paths.expected ).toString('utf8').trim().split('\n').map(fuzzy) );

t.end();
});
Expand Down Expand Up @@ -197,13 +197,13 @@ module.exports.functional.tsv = function(test) {
action.tsv(test, paths, 'id=1');
};

module.exports.all = function (tape) {
module.exports.all = function (tape, common) {

function test(name, testFunction) {
return tape('functional: lueppold road: ' + name, testFunction);
}

for( var testCase in module.exports.functional ){
module.exports.functional[testCase](test);
module.exports.functional[testCase](test, common);
}
};
8 changes: 4 additions & 4 deletions test/functional/nevern_square/reports/preview.geojson
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@
"lon": -0.196344,
"parity": "R",
"proj_lat": 51.4915811139076,
"proj_lon": -0.196505604725702,
"proj_lon": -0.196505604725703,
"marker-color": "#ff0000",
"marker-symbol": "e"
},
Expand Down Expand Up @@ -362,7 +362,7 @@
"lat": 51.492682,
"lon": -0.196952,
"parity": "L",
"proj_lat": 51.4925351714597,
"proj_lat": 51.4925351714598,
"proj_lon": -0.196822421886882,
"marker-color": "#3366ff",
"marker-symbol": "o"
Expand Down Expand Up @@ -637,7 +637,7 @@
51.491497
],
[
-0.196505604725702,
-0.196505604725703,
51.4915811139076
]
]
Expand Down Expand Up @@ -758,7 +758,7 @@
],
[
-0.196822421886882,
51.4925351714597
51.4925351714598
]
]
}
Expand Down
4 changes: 2 additions & 2 deletions test/functional/nevern_square/reports/preview.tsv
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ rowid id source source_id housenumber lat lon parity proj_lat proj_lon
27 1 VERTEX 13.525 51.491878 -0.196107
18 1 OSM way:108009866 18.0 51.491618 -0.196181 R 51.4917022800645 -0.196342924815903
14 1 OSM way:108009860 19.0 51.491572 -0.196243 R 51.4916562067692 -0.196404783669249
17 1 OSM way:108009865 20.0 51.491497 -0.196344 R 51.4915811139076 -0.196505604725702
17 1 OSM way:108009865 20.0 51.491497 -0.196344 R 51.4915811139076 -0.196505604725703
26 1 VERTEX 22.643 51.491519 -0.196589
7 1 OSM way:87307121 30.0 51.491524 -0.197048 R 51.491660727619 -0.196870307849919
5 1 OSM way:87307110 40.0 51.49193 -0.197822 R 51.4920570299912 -0.197656908012922
4 1 OSM way:87307105 41.0 51.491973 -0.197903 R 51.4920987059475 -0.197739628471638
1 1 OSM way:87303089 42.0 51.492026 -0.198009 R 51.4921065737614 -0.198088456441266
2 1 OSM way:87303105 44.0 51.491544 -0.197749 R 51.4918820707879 -0.197309640503272
13 1 OSM way:87313566 59.0 51.492682 -0.196952 L 51.4925351714597 -0.196822421886882
13 1 OSM way:87313566 59.0 51.492682 -0.196952 L 51.4925351714598 -0.196822421886882
11 1 OSM way:87313555 60.0 51.492712 -0.196865 L 51.492564989586 -0.196735261210157
8 1 OSM way:87313545 61.0 51.492741 -0.196779 L 51.4925943130401 -0.19664954649828
12 1 OSM way:87313559 62.0 51.492771 -0.196692 L 51.4926241311664 -0.196562385821362
Expand Down
8 changes: 4 additions & 4 deletions test/functional/nevern_square/run.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,12 +99,12 @@ module.exports.functional.spotcheck = function(test) {
});
};

module.exports.functional.end_to_end = function(test) {
module.exports.functional.end_to_end = function(test, { fuzzy }) {
test('end to end', function(t) {

// full interpolation for a single street
var rows = sqlite3.exec( paths.db.address, 'SELECT * FROM address WHERE id=1 ORDER BY housenumber' );
t.deepEqual(rows, fs.readFileSync( paths.expected ).toString('utf8').trim().split('\n') );
t.deepEqual(rows.map(fuzzy), fs.readFileSync( paths.expected ).toString('utf8').trim().split('\n').map(fuzzy) );

t.end();
});
Expand Down Expand Up @@ -225,13 +225,13 @@ module.exports.functional.tsv = function(test) {
action.tsv(test, paths, 'id=1');
};

module.exports.all = function (tape) {
module.exports.all = function (tape, common) {

function test(name, testFunction) {
return tape('functional: nevern square: ' + name, testFunction);
}

for( var testCase in module.exports.functional ){
module.exports.functional[testCase](test);
module.exports.functional[testCase](test, common);
}
};
Loading

0 comments on commit 3c4d6d3

Please sign in to comment.