aboutsummaryrefslogtreecommitdiff
path: root/test/reduceRangeDuplicates.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/reduceRangeDuplicates.js')
-rw-r--r--test/reduceRangeDuplicates.js85
1 files changed, 60 insertions, 25 deletions
diff --git a/test/reduceRangeDuplicates.js b/test/reduceRangeDuplicates.js
index 091390c..21c80c4 100644
--- a/test/reduceRangeDuplicates.js
+++ b/test/reduceRangeDuplicates.js
@@ -3,7 +3,7 @@ const fs = require('fs')
const child_process = require('child_process')
const mktemp = require('mktemp')
-function createFeature(unit, housenumber, street, suburb, flats) {
+function createFeature(coordinates, unit, housenumber, street, suburb, flats) {
return {
type: 'Feature',
properties: {
@@ -15,18 +15,21 @@ function createFeature(unit, housenumber, street, suburb, flats) {
'addr:state': 'VIC',
'addr:postcode': '0000'
},
- geometry: null
+ geometry: coordinates ? {
+ type: 'Point',
+ coordinates: coordinates
+ } : null
}
}
-test('reduceRangeDuplicates', t => {
+test('reduceRangeDuplicates distinct geometries', 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 AB = createFeature(null, '304-306', 'Cardigan Street', 'Carlton')
- const A = createFeature(null, '304', 'Cardigan Street', 'Carlton')
- const B = createFeature(null, '306', 'Cardigan Street', 'Carlton')
+ const AB = createFeature([0, 0], null, '304-306', 'Cardigan Street', 'Carlton')
+ const A = createFeature([-1, 0], null, '304', 'Cardigan Street', 'Carlton')
+ const B = createFeature([1, 0], null, '306', 'Cardigan Street', 'Carlton')
// all three features to appear in input
fs.appendFileSync(inputFile, JSON.stringify(AB) + '\n')
@@ -37,11 +40,11 @@ test('reduceRangeDuplicates', t => {
fs.appendFileSync(expectedFile, JSON.stringify(A) + '\n')
fs.appendFileSync(expectedFile, JSON.stringify(B) + '\n')
- child_process.execSync(`./bin/reduceRangeDuplicates.js ${inputFile} ${outputFile}`)
+ child_process.execSync(`./bin/reduceRangeDuplicates.js --verbose ${inputFile} ${outputFile}`)
t.same(
- fs.readFileSync(outputFile),
- fs.readFileSync(expectedFile),
+ fs.readFileSync(outputFile, 'utf-8').trim().split('\n').map(JSON.parse),
+ fs.readFileSync(expectedFile, 'utf-8').trim().split('\n').map(JSON.parse),
'range with endpoints appearing separately, drops range'
)
@@ -52,13 +55,45 @@ test('reduceRangeDuplicates', t => {
t.end()
})
+test('reduceRangeDuplicates overlapping geometries', 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 AB = createFeature([0, 0], null, '304-306', 'Cardigan Street', 'Carlton')
+ const A = createFeature([0, 0], null, '304', 'Cardigan Street', 'Carlton')
+ const B = createFeature([0, 0], null, '306', 'Cardigan Street', 'Carlton')
+
+ // all three features to appear in input
+ fs.appendFileSync(inputFile, JSON.stringify(AB) + '\n')
+ fs.appendFileSync(inputFile, JSON.stringify(A) + '\n')
+ fs.appendFileSync(inputFile, JSON.stringify(B) + '\n')
+
+ // output expected to drop the endpoints and retain the range since endpoints are overlapping
+ fs.appendFileSync(expectedFile, JSON.stringify(AB) + '\n')
+
+ child_process.execSync(`./bin/reduceRangeDuplicates.js --verbose ${inputFile} ${outputFile}`)
+
+ t.same(
+ fs.readFileSync(outputFile, 'utf-8').trim().split('\n').map(JSON.parse),
+ fs.readFileSync(expectedFile, 'utf-8').trim().split('\n').map(JSON.parse),
+ 'range with endpoints appearing separately but overlapping, drops the endpoints'
+ )
+
+ fs.unlinkSync(inputFile)
+ fs.unlinkSync(outputFile)
+ fs.unlinkSync(expectedFile)
+
+ 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')
+ const AC = createFeature(null, null, '249-263', 'Faraday Street', 'Carlton')
+ const B = createFeature(null, null, '251', 'Faraday Street', 'Carlton')
// both features to appear in input
fs.appendFileSync(inputFile, JSON.stringify(AC) + '\n')
@@ -67,11 +102,11 @@ test('reduceRangeDuplicates', t => {
// output expected to just be range, dropping the midpoint
fs.appendFileSync(expectedFile, JSON.stringify(AC) + '\n')
- child_process.execSync(`./bin/reduceRangeDuplicates.js ${inputFile} ${outputFile}`)
+ child_process.execSync(`./bin/reduceRangeDuplicates.js --verbose ${inputFile} ${outputFile}`)
t.same(
- fs.readFileSync(outputFile),
- fs.readFileSync(expectedFile),
+ fs.readFileSync(outputFile, 'utf-8').trim().split('\n').map(JSON.parse),
+ fs.readFileSync(expectedFile, 'utf-8').trim().split('\n').map(JSON.parse),
'range with lone midpoint, drops midpoint'
)
@@ -87,8 +122,8 @@ test('reduceRangeDuplicates', t => {
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')
+ const AC = createFeature(null, null, '249-263', 'Faraday Street', 'Carlton')
+ const B = createFeature(null, '1', '251', 'Faraday Street', 'Carlton')
// both features to appear in input
fs.appendFileSync(inputFile, JSON.stringify(AC) + '\n')
@@ -98,11 +133,11 @@ test('reduceRangeDuplicates', t => {
fs.appendFileSync(expectedFile, JSON.stringify(AC) + '\n')
fs.appendFileSync(expectedFile, JSON.stringify(B) + '\n')
- child_process.execSync(`./bin/reduceRangeDuplicates.js ${inputFile} ${outputFile}`)
+ child_process.execSync(`./bin/reduceRangeDuplicates.js --verbose ${inputFile} ${outputFile}`)
t.same(
- fs.readFileSync(outputFile),
- fs.readFileSync(expectedFile),
+ fs.readFileSync(outputFile, 'utf-8').trim().split('\n').map(JSON.parse),
+ fs.readFileSync(expectedFile, 'utf-8').trim().split('\n').map(JSON.parse),
'midpoint with unit not dropped'
)
@@ -118,22 +153,22 @@ test('reduceRangeDuplicates', t => {
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')
+ const AC = createFeature(null, null, '249-263', 'Faraday Street', 'Carlton')
+ const B = createFeature(null, 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
+ // output expected to both features because dropping the midpoint would loose the flats
fs.appendFileSync(expectedFile, JSON.stringify(AC) + '\n')
fs.appendFileSync(expectedFile, JSON.stringify(B) + '\n')
- child_process.execSync(`./bin/reduceRangeDuplicates.js ${inputFile} ${outputFile}`)
+ child_process.execSync(`./bin/reduceRangeDuplicates.js --verbose ${inputFile} ${outputFile}`)
t.same(
- fs.readFileSync(outputFile),
- fs.readFileSync(expectedFile),
+ fs.readFileSync(outputFile, 'utf-8').trim().split('\n').map(JSON.parse),
+ fs.readFileSync(expectedFile, 'utf-8').trim().split('\n').map(JSON.parse),
'midpoint with flats not dropped'
)