prosperon/scripts/test.js

53 lines
832 B
JavaScript
Raw Normal View History

2024-03-14 10:21:44 -05:00
/* Tests for prosperon */
2024-08-20 02:17:56 -05:00
var test = {};
2024-03-14 10:21:44 -05:00
var tests = [];
var pass = 0;
var fail = 0;
var failed = [];
2024-03-14 10:21:44 -05:00
2024-08-20 02:17:56 -05:00
test.run_suite = function(file)
{
test = [];
pass = 0;
fail = 0;
failed = [];
}
test.run = function(name, fn)
2024-03-14 10:21:44 -05:00
{
var func = function() {
print(`${pass+fail+1}/${tests.length}: ${name} ... `);
var p = profile.now();
var b = fn();
p = profile.lap(p);
print(`${b ? "pass" : "fail"} [${p}]`);
return b;
};
func.testname = name;
tests.push(func);
2024-03-14 10:21:44 -05:00
}
say(`Testing ${tests.length} tests.`);
for (var t of tests) {
if (t())
pass++;
else {
2024-03-14 10:21:44 -05:00
fail++;
failed.push(t.testname);
}
2024-03-14 10:21:44 -05:00
print("\n");
}
say(`Passed ${pass} tests and failed ${fail} [${(pass*100/(pass+fail)).toPrecision(4)}%].`);
say(`Failed tests are:`);
for (var f of failed)
say(f);
2024-03-15 11:21:36 -05:00
os.quit();
2024-08-20 02:17:56 -05:00
return {test};