-
-
Notifications
You must be signed in to change notification settings - Fork 150
/
Copy pathindex.js
62 lines (48 loc) · 1.25 KB
/
index.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
"use strict";
function assert(condition) {
if (!condition) {
throw "Assert failed";
}
}
function testExpoCurve() {
var
curve = new ExpoCurve(0, 0.700, 750, 1.0, 10);
assert(curve.lookup(0) == 0.0);
assert(curve.lookup(-750) == -1.0);
assert(curve.lookup(750) == 1.0);
}
function testExpoStraightLine() {
var
curve = new ExpoCurve(0, 1.0, 500, 1.0, 1);
assert(curve.lookup(0) == 0.0);
assert(curve.lookup(-500) == -1.0);
assert(curve.lookup(500) == 1.0);
assert(curve.lookup(-250) == -0.5);
assert(curve.lookup(250) == 0.5);
}
function benchExpoCurve() {
var
trial, i,
curve = new ExpoCurve(0, 0.700, 750, 1.0, 10),
acc = 0,
endTime, results = "";
for (trial = 0; trial < 10; trial++) {
var
start = Date.now(),
end;
for (i = 0; i < 10000000; i++) {
acc += curve.lookup(Math.random() * 750);
}
end = Date.now();
results += (end - start) + "\n";
}
alert("Expo curve bench\n" + results);
}
try {
testExpoCurve();
testExpoStraightLine();
//benchExpoCurve();
alert("All tests pass");
} catch (e) {
alert(e);
}