-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
122 lines (104 loc) · 3.45 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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
require('mocha');
var assert = require('assert');
var round = require('./');
var TEST_VALUE = 10.123456789123;
describe('Exists', function () {
it('should export a function', function () {
assert.equal(typeof round, 'function');
});
});
describe('Validation', function () {
it('should throw on wrong latitude', function () {
assert.throws(function () {
round(91, 0, 1000);
}, RangeError);
assert.throws(function () {
round(-91, 0, 1000);
}, RangeError);
});
it('should throw on wrong longitude', function () {
assert.throws(function () {
round(0, 181, 1000);
}, RangeError);
assert.throws(function () {
round(0, -181, 1000);
}, RangeError);
});
it('should throw on wrong precision', function () {
assert.throws(function () {
round(0, 0, 0);
}, RangeError);
assert.throws(function () {
round(0, 0, -100);
}, RangeError);
});
it('should accept too large precision', function () {
var value = round(TEST_VALUE, TEST_VALUE, Number.POSITIVE_INFINITY);
assert.equal(value.latitude, 10);
assert.equal(value.longitude, 10);
});
});
describe('Calculations in meters', function () {
it('should round to 1cm', function () {
var value = round(TEST_VALUE, TEST_VALUE, 0.01);
assert.equal(value.latitude, 10.12345679);
assert.equal(value.longitude, 10.12345679);
});
it('should round to 1m', function () {
var value = round(TEST_VALUE, TEST_VALUE, 1);
assert.equal(value.latitude, 10.123457);
assert.equal(value.longitude, 10.123457);
});
it('should round to 100m', function () {
var value = round(TEST_VALUE, TEST_VALUE, 100);
assert.equal(value.latitude, 10.1235);
assert.equal(value.longitude, 10.1235);
});
it('should round to 1km', function () {
var value = round(TEST_VALUE, TEST_VALUE, 1000);
assert.equal(value.latitude, 10.123);
assert.equal(value.longitude, 10.123);
});
it('should round to 100km', function () {
var value = round(TEST_VALUE, TEST_VALUE, 100000);
assert.equal(value.latitude, 10.1);
assert.equal(value.longitude, 10.1);
});
it('should round with different precision', function () {
var value = round(89.123456789123, TEST_VALUE, 1000);
assert.equal(value.latitude, 89.123);
assert.equal(value.longitude, 10.1);
});
it('should work on south pole', function () {
var value = round(90, TEST_VALUE, 1000);
assert.equal(value.latitude, 90);
assert.equal(value.longitude, 10);
});
it('should work on north pole', function () {
var value = round(-90, TEST_VALUE, 1000);
assert.equal(value.latitude, -90);
assert.equal(value.longitude, 10);
});
it('should not modify coordinates', function () {
var value = round(12.12, 15.15, 1);
assert.equal(value.latitude, 12.12);
assert.equal(value.longitude, 15.15);
});
});
describe('Calculations in yards', function () {
it('should round to 1 yd', function () {
var value = round(TEST_VALUE, TEST_VALUE, 1, true);
assert.equal(value.latitude, 10.123457);
assert.equal(value.longitude, 10.123457);
});
it('should round to 1000 yd', function () {
var value = round(TEST_VALUE, TEST_VALUE, 1000, true);
assert.equal(value.latitude, 10.123);
assert.equal(value.longitude, 10.123);
});
it('should not modify coordinates', function () {
var value = round(12.12, 15.15, 1, true);
assert.equal(value.latitude, 12.12);
assert.equal(value.longitude, 15.15);
});
});