forked from ianengelbrecht/geo-coordinates-parser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
53 lines (38 loc) · 1.43 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
const convert = require('./converter')
const testFormats = require('./testformats')
let allPassed = true;
//find the first one that doesn't work
testFormats.some(t => { //.some so we can break
try {
var converted = convert(t.verbatimCoordinates, 8)
var testDecimalCoordsString = `${t.decimalLatitude},${t.decimalLongitude}`
//check the calculation is correct
if(!converted.closeEnough(testDecimalCoordsString)) {
console.log("Error in decimal conversion")
console.log(t.verbatimCoordinates)
console.log(t.decimalLatitude)
console.log(t.decimalLongitude)
allPassed = false;
return true;
}
//check the verbatim coords are correct
if(converted.verbatimLatitude != t.verbatimLatitude || converted.verbatimLongitude != t.verbatimLongitude) {
console.log("Error in verbatim extraction")
console.log('For', t.verbatimCoordinates)
console.log('got', converted.verbatimLatitude, 'should be ', t.verbatimLatitude)
console.log('got', converted.verbatimLongitude, 'should be', t.verbatimLongitude)
allPassed = false;
return true
}
}
catch(err) {
console.log("Failed to convert the following format")
console.log(t.verbatimCoordinates)
console.log(err.message)
allPassed = false;
return true;
}
})
if (allPassed) {
console.log("all formats successfully converted")
}