diff options
author | Andrew Harvey <andrew@alantgeo.com.au> | 2021-05-04 14:50:52 +1000 |
---|---|---|
committer | Andrew Harvey <andrew@alantgeo.com.au> | 2021-05-04 14:50:52 +1000 |
commit | 5039b0dbf3af3b93466069927d794f5b1c8ccf81 (patch) | |
tree | 82f675877771b06da8cd4b82778c68b65d11cb91 /test | |
parent | 0e9a1861bac8b310c757a2c3fd92d67b50ebba12 (diff) |
add cluster library
Diffstat (limited to 'test')
-rw-r--r-- | test/cluster.js | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/test/cluster.js b/test/cluster.js new file mode 100644 index 0000000..ddec552 --- /dev/null +++ b/test/cluster.js @@ -0,0 +1,83 @@ +const test = require('tape') + +const cluster = require('../cluster.js') + +const A = { + type: 'Feature', + id: 'A', + properties: {}, + geometry: { + type: 'Point', + coordinates: [0, 0] + } +} + +const B = { + type: 'Feature', + id: 'B', + properties: {}, + geometry: { + type: 'Point', + coordinates: [0, 0] + } +} + +const C = { + type: 'Feature', + id: 'C', + properties: {}, + geometry: { + type: 'Point', + coordinates: [0.000001, 0.000001] + } +} + +const D = { + type: 'Feature', + id: 'D', + properties: {}, + geometry: { + type: 'Point', + coordinates: [1, 1] + } +} + +test('cluster', t => { + t.same( + cluster([], 100), + [], + 'empty input returns empty output' + ) + + t.same( + cluster([A], 100), + [[A]], + 'single feature input returns single feature output cluster' + ) + + t.same( + cluster([A, B], 100), + [[A, B]], + 'overlapping points clustered' + ) + + t.same( + cluster([A, C], 100), + [[A, C]], + 'nearby points clustered' + ) + + t.same( + cluster([A, D], 100), + [[A], [D]], + 'far away points not clustered' + ) + + t.same( + cluster([A, B, C, D], 100), + [[A, B, C], [D]], + 'some clustered others not' + ) + + t.end() +}) |