-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
53 lines (49 loc) · 1.54 KB
/
Copy pathtest.js
File metadata and controls
53 lines (49 loc) · 1.54 KB
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
'use strict';
import test from 'tape';
import {getLength} from './utils.js'
import midPoint from './index.js'
test('lengths', (t) => {
var a = [0, 0];
var b = [1, 1];
var c = [-1, -1];
var root2 = Math.sqrt(2);
var root8 = Math.sqrt(8);
t.plan(6);
t.equals(getLength(a, b), root2);
t.equals(getLength(a, c), root2);
t.equals(getLength(b, c), root8);
t.equals(getLength(b, a), root2);
t.equals(getLength(c, a), root2);
t.equals(getLength(c, b), root8);
});
test('mid points', function (t) {
t.deepEquals(midPoint([[0,0], [1,1], [2,2], [3,3]]), [1.5, 1.5], 'correct mid point 1');
t.deepEquals(midPoint([[0,0], [1,1], [3,3]]), [1.5, 1.5], 'correct mid point, 2');
t.deepEquals(midPoint([[0,0], [1,1],[2,2]]), [1, 1], 'correct mid point, 3');
t.deepEquals(midPoint([[0,0], [1, 0],[1,1],[7,1]]), [3, 1], 'correct mid point, 4');
t.deepEquals(midPoint([[7,1], [1,1],[1,0],[0,0]]), [3, 1], 'correct mid point, 5');
t.end();
});
test('weird', (t) => {
const path = [
[
-93.58900674667849,
34.72896579327973
],
[
-93.52014326672906,
34.88244373300708
],
[
-93.31354710277073,
34.9711667901214
],
[
-89.36857824131185,
35.22873356176132
]
]
t.deepEquals(midPoint(path), [-91.53717547300896, 35.08714598336179], 'correct forward')
t.deepEquals(midPoint(path.toReversed()), [-91.53717547300896, 35.08714598336179 ], 'correct backwards')
t.end();
});