aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--test/reduceRangeDuplicates.js44
1 files changed, 38 insertions, 6 deletions
diff --git a/test/reduceRangeDuplicates.js b/test/reduceRangeDuplicates.js
index e180841..04b69e1 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(housenumber, street, suburb) {
+function createFeature(unit, housenumber, street, suburb) {
return {
type: 'Feature',
properties: {
+ ...(unit && {'addr:unit': unit}),
'addr:housenumber': housenumber,
'addr:street': street,
'addr:suburb': suburb,
@@ -22,9 +23,9 @@ test('reduceRangeDuplicates', t => {
const outputFile = mktemp.createFileSync('/tmp/output_XXXXX.geojson')
const expectedFile = mktemp.createFileSync('/tmp/expected_XXXXX.geojson')
- const AB = createFeature('304-306', 'Cardigan Street', 'Carlton')
- const A = createFeature('304', 'Cardigan Street', 'Carlton')
- const B = createFeature('306', 'Cardigan Street', 'Carlton')
+ const AB = createFeature(null, '304-306', 'Cardigan Street', 'Carlton')
+ const A = createFeature(null, '304', 'Cardigan Street', 'Carlton')
+ const B = createFeature(null, '306', 'Cardigan Street', 'Carlton')
// all three features to appear in input
fs.appendFileSync(inputFile, JSON.stringify(AB) + '\n')
@@ -55,8 +56,8 @@ test('reduceRangeDuplicates', t => {
const outputFile = mktemp.createFileSync('/tmp/output_XXXXX.geojson')
const expectedFile = mktemp.createFileSync('/tmp/expected_XXXXX.geojson')
- const AC = createFeature('249-263', 'Faraday Street', 'Carlton')
- const B = createFeature('251', 'Faraday Street', 'Carlton')
+ const AC = createFeature(null, '249-263', 'Faraday Street', 'Carlton')
+ const B = createFeature(null, '251', 'Faraday Street', 'Carlton')
// both features to appear in input
fs.appendFileSync(inputFile, JSON.stringify(AC) + '\n')
@@ -79,3 +80,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('1', '251', 'Faraday Street', 'Carlton')
+
+ // 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 unit not dropped'
+ )
+
+ fs.unlinkSync(inputFile)
+ fs.unlinkSync(outputFile)
+ fs.unlinkSync(expectedFile)
+
+ t.end()
+})