diff options
author | Andrew Harvey <andrew@alantgeo.com.au> | 2021-05-15 21:13:00 +1000 |
---|---|---|
committer | Andrew Harvey <andrew@alantgeo.com.au> | 2021-05-15 21:13:00 +1000 |
commit | b8e3db9f16fe2e82cd6ab80a6f5ad97cc881ebd7 (patch) | |
tree | 3b30bae037b54d5ae81f05d579809a20671044d4 /test | |
parent | 3f5a8c25bba4d459238deeaf7042f59f69e9d4ab (diff) |
test flats inside range
Diffstat (limited to 'test')
-rw-r--r-- | test/reduceRangeDuplicates.js | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/test/reduceRangeDuplicates.js b/test/reduceRangeDuplicates.js index 04b69e1..091390c 100644 --- a/test/reduceRangeDuplicates.js +++ b/test/reduceRangeDuplicates.js @@ -3,10 +3,11 @@ const fs = require('fs') const child_process = require('child_process') const mktemp = require('mktemp') -function createFeature(unit, housenumber, street, suburb) { +function createFeature(unit, housenumber, street, suburb, flats) { return { type: 'Feature', properties: { + ...(flats && {'addr:flats': flats}), ...(unit && {'addr:unit': unit}), 'addr:housenumber': housenumber, 'addr:street': street, @@ -111,3 +112,34 @@ test('reduceRangeDuplicates', t => { t.end() }) + +test('reduceRangeDuplicates', t => { + const inputFile = mktemp.createFileSync('/tmp/input_XXXXX.geojson') + const outputFile = mktemp.createFileSync('/tmp/output_XXXXX.geojson') + const expectedFile = mktemp.createFileSync('/tmp/expected_XXXXX.geojson') + + const AC = createFeature(null, '249-263', 'Faraday Street', 'Carlton') + const B = createFeature(null, '251', 'Faraday Street', 'Carlton', '1;2;3') + + // both features to appear in input + fs.appendFileSync(inputFile, JSON.stringify(AC) + '\n') + fs.appendFileSync(inputFile, JSON.stringify(B) + '\n') + + // output expected to both features because dropping the midpoint would loose the unit + fs.appendFileSync(expectedFile, JSON.stringify(AC) + '\n') + fs.appendFileSync(expectedFile, JSON.stringify(B) + '\n') + + child_process.execSync(`./bin/reduceRangeDuplicates.js ${inputFile} ${outputFile}`) + + t.same( + fs.readFileSync(outputFile), + fs.readFileSync(expectedFile), + 'midpoint with flats not dropped' + ) + + fs.unlinkSync(inputFile) + fs.unlinkSync(outputFile) + fs.unlinkSync(expectedFile) + + t.end() +}) |