forked from max-mapper/simplify-geojson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
102 lines (84 loc) · 3.54 KB
/
test.js
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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var test = require('tape')
var fs = require('fs')
var concat = require('concat-stream')
var proc = require('child_process')
var spawn = proc.spawn
var exec = proc.exec
var simplify = require('./')
test('FeatureCollection w/ a LineString in it', function (t) {
var fcLine = JSON.parse(fs.readFileSync('./test-data/oakland-route.geojson'))
var len = fcLine.features[0].geometry.coordinates.length
var simplified = simplify(fcLine, 0.001)
var newLen = simplified.features[0].geometry.coordinates.length
t.true(newLen < len, 'should get simplified (' + newLen + ' < ' + len + ')')
t.end()
})
test('FeatureCollection w/ a LineString in it (cli)', function (t) {
t.plan(1)
var file = './test-data/oakland-route.geojson'
var fcLine = JSON.parse(fs.readFileSync('./test-data/oakland-route.geojson'))
var len = fcLine.features[0].geometry.coordinates.length
var proc = spawn('./cli.js', [file, '-t 0.001'])
proc.stderr.on('data', function (data) {
t.error(data.toString(), 'does not error')
})
proc.stdout.pipe(concat(function (buffer) {
var simplified = JSON.parse(buffer.toString())
var newLen = simplified.features[0].geometry.coordinates.length
t.true(newLen < len, 'should get simplified (' + newLen + ' < ' + len + ')')
}))
})
test('FeatureCollection w/ a MultiPolygon in it', function (t) {
var fsMp = JSON.parse(fs.readFileSync('./test-data/alaska.geojson'))
var len = JSON.stringify(fsMp, null, ' ').split('\n').length
var simplified = simplify(fsMp, 0.5)
var newLen = JSON.stringify(simplified, null, ' ').split('\n').length
t.true(newLen < len, 'should get simplified (' + newLen + ' < ' + len + ')')
t.end()
})
test('Polygon', function (t) {
var fsMp = JSON.parse(fs.readFileSync('./test-data/polygon.geojson'))
var len = JSON.stringify(fsMp, null, ' ').split('\n').length
var simplified = simplify(fsMp, 0.5)
var newLen = JSON.stringify(simplified, null, ' ').split('\n').length
t.true(newLen < len, 'should get simplified (' + newLen + ' < ' + len + ')')
t.end()
})
test('MultiLineString', function (t) {
var fsMp = JSON.parse(fs.readFileSync('./test-data/multilinestring.geojson'))
var len = JSON.stringify(fsMp, null, ' ').split('\n').length
var simplified = simplify(fsMp, 0.5)
var newLen = JSON.stringify(simplified, null, ' ').split('\n').length
t.true(newLen < len, 'should get simplified (' + newLen + ' < ' + len + ')')
t.end()
})
test('FeatureCollection w/ a MultiPolygon in it (cli)', function (t) {
t.plan(1)
var file = './test-data/alaska.geojson'
var fsMp = JSON.parse(fs.readFileSync(file))
var len = JSON.stringify(fsMp, null, ' ').split('\n').length
var proc = spawn('./cli.js', [file, '-t 0.5'])
proc.stderr.on('data', function (data) {
t.error(data.toString(), 'does not error')
})
proc.stdout.pipe(concat(function (buffer) {
var geoJson = JSON.parse(buffer.toString())
var newLen = JSON.stringify(geoJson, null, ' ').split('\n').length
t.true(newLen < len, 'should get simplified (' + newLen + ' < ' + len + ')')
}))
})
test('curl from alaska example test', function (t) {
t.plan(1)
var cmd = 'curl -s https://rawgit.com/johan/world.geo.json/master/countries/USA/AK.geo.json | '
cmd += './cli.js -t 0.01 | '
cmd += 'wc -l'
var proc = exec(cmd)
proc.stderr.on('data', function (data) {
t.error(data.toString(), 'does not error')
})
proc.stdout.pipe(concat(function (buffer) {
var len = JSON.parse(buffer.toString())
t.false(isNaN(+len), 'got a valid number back (' + len + ')')
}))
})
// TODO tests for other types (send me a PR :D)