From 5039b0dbf3af3b93466069927d794f5b1c8ccf81 Mon Sep 17 00:00:00 2001 From: Andrew Harvey Date: Tue, 4 May 2021 14:50:52 +1000 Subject: add cluster library --- test/cluster.js | 83 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 83 insertions(+) create mode 100644 test/cluster.js (limited to 'test/cluster.js') 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() +}) -- cgit v1.2.3