ensilico
Version:
Synthetic data generation, simulated vehicles
63 lines (55 loc) • 1.5 kB
HTML
<html>
<head>
<title>
Tests
</title>
<script>
MyClass.indexOf = (function() {
function areEqual(a, b) {
return a === b;
}
return Selftest
.describe("The first index of a value")
.with([], 7).returns(-1)
.with([3], 7).returns(-1)
.with([3], 3).returns(0)
.with([2, 4, 7], 7).returns(2)
.assert(function(a, n) {
var result = -1;
for (var i = 0; i < a.length; i++) {
if (areEqual(a[i], n)) {
result = i;
break;
}
}
return result;
});
})();
MyClass.lerp = (function() {
function small() {
return Math.pow(2, -60); // or whatever
}
var myTest = Selftest
.describe("Linear interpolation")
.with(small(), 1, 0).returns(small());
myTest.refute(function(f1, f2, t) {
return f1 + (f2 - f1) * t;
});
return myTest.assert(function(f1, f2, t) {
return (1 - t) * f1 + t * f2;
});
})();
function Clock() {
this.time = 0;
}
Clock.prototype.add = Selftest
.describe("Add time")
.start({time: 0}).with(3).end({time: 3})
.assert(function(delta) {
this.time += delta;
});
</script>
</head>
<body>
</body>
</html>