aboutsummaryrefslogtreecommitdiff
path: root/test/cluster.js
blob: 51d60a17d55bbf2ff0e83a5797eb9522e2e5300a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
const test = require('tape')

const cluster = require('../lib/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()
})