Skip to content

Commit

Permalink
Expo curve tests
Browse files Browse the repository at this point in the history
  • Loading branch information
thenickdude committed May 12, 2015
1 parent d5fd151 commit 1f69a6b
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
14 changes: 14 additions & 0 deletions test/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Blackbox viewer tests</title>

<script type="text/javascript" src="../js/expo.js"></script>

<script type="text/javascript" src="index.js"></script>
</head>
<body>

</body>
</html>
62 changes: 62 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);
}

0 comments on commit 1f69a6b

Please sign in to comment.