From 0275d9e79da1f72044737fb0fbcaa4f136f09c6f Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Mon, 5 Jul 2021 12:01:04 +1000 Subject: update within range to accept comparing ranges --- test/withinRange.js | 97 +++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 95 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/withinRange.js b/test/withinRange.js index 8d46eba..c2d37de 100644 --- a/test/withinRange.js +++ b/test/withinRange.js @@ -93,6 +93,75 @@ const rangeOutsideSub = { } } +const B_withSuburb = { + "type": "Feature", + "properties": { + "addr:housenumber": "2", + "addr:street": "Main Street", + "addr:suburb": "Suburb A" + }, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } +} +const AC_withDifferentSuburb = { + "type": "Feature", + "properties": { + "addr:housenumber": "1-3", + "addr:street": "Main Street", + "addr:suburb": "Suburb B" + }, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } +} + +const AD = { + "type": "Feature", + "properties": { + "addr:housenumber": "1-4", + "addr:street": "Main Street" + }, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } +} +const BC = { + "type": "Feature", + "properties": { + "addr:housenumber": "2-3", + "addr:street": "Main Street" + }, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } +} +const CE = { + "type": "Feature", + "properties": { + "addr:housenumber": "3-5", + "addr:street": "Main Street" + }, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } +} +const DE = { + "type": "Feature", + "properties": { + "addr:housenumber": "4-5", + "addr:street": "Main Street" + }, + "geometry": { + "type": "Point", + "coordinates": [0, 0] + } +} test('withinRange', t => { t.same( @@ -138,9 +207,33 @@ test('withinRange', t => { ) t.same( - withinRange(A, AC, { matchParity: true }), + withinRange(B_withSuburb, AC_withDifferentSuburb), + false, + 'by default checks suburbs match for within to pass' + ) + + t.same( + withinRange(B_withSuburb, AC_withDifferentSuburb, { + checkHigherOrderAddrKeys: false + }), + true, + 'within range when ignoring higher order addr keys' + ) + + t.same( + withinRange(BC, AD), + true, + 'range completely within range' + ) + t.same( + withinRange(CE, AD), + true, + 'range overlapping within range' + ) + t.same( + withinRange(DE, AD), true, - 'A within AC when matching parity' + 'range touching endpoints of range' ) t.end() -- cgit v1.2.3