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;
|
2024-03-14 14:10:06 -05:00
|
|
|
var failed = [];
|
2024-03-14 10:21:44 -05:00
|
|
|
|
2024-09-26 11:36:09 -05:00
|
|
|
test.run_suite = function (file) {
|
2024-08-20 02:17:56 -05:00
|
|
|
test = [];
|
|
|
|
pass = 0;
|
|
|
|
fail = 0;
|
|
|
|
failed = [];
|
2024-09-26 11:36:09 -05:00
|
|
|
};
|
2024-08-20 02:17:56 -05:00
|
|
|
|
2024-09-26 11:36:09 -05:00
|
|
|
test.run = function (name, fn) {
|
|
|
|
var func = function () {
|
|
|
|
print(`${pass + fail + 1}/${tests.length}: ${name} ... `);
|
2024-03-14 14:10:06 -05:00
|
|
|
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-09-26 11:36:09 -05:00
|
|
|
};
|
2024-03-14 10:21:44 -05:00
|
|
|
|
|
|
|
say(`Testing ${tests.length} tests.`);
|
|
|
|
for (var t of tests) {
|
2024-09-26 11:36:09 -05:00
|
|
|
if (t()) pass++;
|
2024-03-14 14:10:06 -05:00
|
|
|
else {
|
2024-03-14 10:21:44 -05:00
|
|
|
fail++;
|
2024-03-14 14:10:06 -05:00
|
|
|
failed.push(t.testname);
|
|
|
|
}
|
2024-03-14 10:21:44 -05:00
|
|
|
print("\n");
|
|
|
|
}
|
|
|
|
|
2024-09-26 11:36:09 -05:00
|
|
|
say(`Passed ${pass} tests and failed ${fail} [${((pass * 100) / (pass + fail)).toPrecision(4)}%].`);
|
2024-03-14 14:10:06 -05:00
|
|
|
say(`Failed tests are:`);
|
2024-09-26 11:36:09 -05:00
|
|
|
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
|
|
|
|
2024-09-26 11:36:09 -05:00
|
|
|
return { test };
|