forked from gheja/trilateration.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
103 lines (77 loc) · 2.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
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
var expect = require("expect");
var trilaterate = require("./trilateration");
var assert = require('assert');
describe('Normal cases', function() {
describe('Two results', function() {
it('First test', function() {
var p1, p2, p3, p4;
p1 = { x: 0, y: 0, z: 0, r: 100 };
p2 = { x: 100, y: 0, z: 0, r: 100 };
p3 = { x: 0, y: 100, z: 0, r: 100 };
p4 = trilaterate(p1, p2, p3);
expect(p4[0].x).toEqual(50);
expect(p4[0].y).toEqual(50);
expect(p4[0].z).toEqual(70.71067811865476);
expect(p4[1].x).toEqual(50);
expect(p4[1].y).toEqual(50);
expect(p4[1].z).toEqual(-70.71067811865476);
});
it('Second test', function() {
var p1, p2, p3, p4;
p1 = { x: 0, y: 0, z: 0, r: 100 };
p2 = { x: 100, y: 0, z: 0, r: 100 };
p3 = { x: 0, y: 100, z: 50, r: 100 };
p4 = trilaterate(p1, p2, p3);
expect(p4[0].x).toEqual(50);
expect(p4[0].y).toEqual(20.419601084501917);
expect(p4[0].z).toEqual(84.16079783099616);
expect(p4[1].x).toEqual(50);
expect(p4[1].y).toEqual(79.58039891549808);
expect(p4[1].z).toEqual(-34.16079783099617);
});
});
describe('One result', function() {
it('First test', function() {
var p1, p2, p3, p4;
p1 = { x: 0, y: 0, z: 0, r: 100 };
p2 = { x: 100, y: 0, z: 0, r: 100 };
p3 = { x: 0, y: 100, z: 50, r: 100 };
p4 = trilaterate(p1, p2, p3, true);
expect(p4.x).toEqual(50);
expect(p4.y).toEqual(50);
expect(p4.z).toEqual(25);
});
});
describe('Zero results', function() {
it('First test', function() {
var p1, p2, p3, p4;
p1 = { x: 0, y: 0, z: 0, r: 10 };
p2 = { x: 100, y: 0, z: 0, r: 10 };
p3 = { x: 0, y: 100, z: 0, r: 10 };
p4 = trilaterate(p1, p2, p3);
expect(p4).toEqual(null);
});
it('Second test', function() {
var p1, p2, p3, p4;
p1 = { x: 0, y: 0, z: 0, r: 10 };
p2 = { x: 100, y: 0, z: 0, r: 10 };
p3 = { x: 0, y: 100, z: 0, r: 10 };
p4 = trilaterate(p1, p2, p3, true);
expect(p4).toEqual(null);
});
});
});
describe('Edge cases', function() {
describe('Floating point math flaw (IEEE 754)', function() {
it('First test', function() {
var p1, p2, p3, p4;
p1 = {x:69, y:0, r:69, z:0}
p2 = {x:0, y:50, r:50, z:0};
p3 = {x:0, y:80, r:80, z:0};
p4 = trilaterate(p1, p2, p3);
expect(p4.x).toEqual(-1.5631940186722204e-13);
expect(p4.y).toEqual(-1.4210854715202004e-13);
expect(p4.z).toEqual(0);
});
});
});