This repository was archived by the owner on Apr 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.js
More file actions
108 lines (96 loc) · 2.34 KB
/
Copy pathtest.js
File metadata and controls
108 lines (96 loc) · 2.34 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
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
(function() {
"use strict";
var assert, eq, regression;
assert = require("assert");
regression = require("./");
eq = (function() {
var has_length, is_array, is_close_to;
is_array = function(array) {
assert(
Array.isArray(array),
"expected " + JSON.stringify(array) + " to be an Array"
);
};
has_length = function(array, length) {
assert(
array.length === length,
"expected " + JSON.stringify(array) + " to be of length " + length
);
};
is_close_to = function(a, b, error) {
assert(
Math.abs(b - a) < error,
"expected " + a + " to be close to " + b + " (+/- " + error + ")"
);
};
return function(actual, expected, message) {
var i, n;
is_array(expected);
n = expected.length;
is_array(actual);
has_length(actual, n);
for(i = 0; i < n; i++) {
is_close_to(actual[i], expected[i], 0.0001);
}
};
})();
describe("regression", function() {
describe("linear", function() {
it(
"should return the best fit for an overdetermined 2D system",
function() {
eq(
regression.linear(
[
1.0, 1.0,
1.0, 2.0,
1.0, 3.0,
1.0, 4.0
],
[
6.0,
5.0,
7.0,
10.0
],
2
),
[
3.5,
1.4
]
);
}
);
});
describe("sinusoidal", function() {
it(
"should return the best fit for a sinusoidal model with a phase",
function() {
eq(
regression.sinusoidal(
[ 0, 1, 2, 3, 4, 5],
[+1, -1, +1, -1, +1, -1],
Math.PI,
1.5 * Math.PI
),
[0, -1, 1.5 * Math.PI, Math.PI]
);
}
);
it(
"should return the best fit for a sinusoidal model without a phase",
function() {
eq(
regression.sinusoidal(
[ 0, 1, 2, 3, 4, 5],
[+1, -1, +1, -1, +1, -1],
Math.PI
),
[0, 1, 0.5 * Math.PI, Math.PI]
);
}
);
});
});
})();