mirror of
https://github.com/xibyte/jsketcher
synced 2026-02-16 12:24:22 +01:00
improve asserting handling
This commit is contained in:
parent
0a75393423
commit
54522e031c
1 changed files with 20 additions and 7 deletions
|
|
@ -4,15 +4,17 @@ TCAD.test.cases = {};
|
|||
TCAD.test.runSuite = function() {
|
||||
for (var p in TCAD.test.cases) {
|
||||
_log("... Run test " + p);
|
||||
TCAD.test.cases[p].apply();
|
||||
try {
|
||||
TCAD.test.cases[p].apply();
|
||||
} catch (e) {
|
||||
_log("<b class='err'>ERROR: </b>" + e);
|
||||
_log((e.stack+"").replace('\n', '<br />'));
|
||||
|
||||
}
|
||||
}
|
||||
_log("DONE.");
|
||||
};
|
||||
|
||||
function _log(text) {
|
||||
$('#testOutput').append("<div>"+text+"</div>");
|
||||
}
|
||||
|
||||
_loadFixture = function(name) {
|
||||
APP.loadSketch(TCAD.test.fixtures[name]);
|
||||
};
|
||||
|
|
@ -25,16 +27,27 @@ _loadFixturesToLocalStorage = function() {
|
|||
}
|
||||
};
|
||||
|
||||
TCAD.test._ERROR_TITLE = "<b class='err'>*</b> Assertion Error.";
|
||||
|
||||
|
||||
function _log(text) {
|
||||
$('#testOutput').append("<div>"+text+"</div>");
|
||||
}
|
||||
|
||||
function _logAssert(msg) {
|
||||
_log(TCAD.test._ERROR_TITLE + " " + msg + "<br/> " + new Error("").stack.split('\n')[3]);
|
||||
}
|
||||
|
||||
_assertEq = function(expected, actual, msg) {
|
||||
if (expected !== actual) {
|
||||
_log("<b class='err'>*</b> Assertion Error. Expected [" + expected + "], but was [" + actual + "]");
|
||||
_logAssert("Expected [" + expected + "], but was [" + actual + "]");
|
||||
if (!!msg) _log(msg);
|
||||
}
|
||||
};
|
||||
|
||||
_assertEqD = function(expected, actual, precision, msg) {
|
||||
if (Math.abs(expected - actual) > precision) {
|
||||
_log("<b class='err'>*</b> Assertion Error. Expected [" + expected + "] with precision " + precision + " but was [" + actual + "]");
|
||||
_logAssert("Expected [" + expected + "] with precision " + precision + " but was [" + actual + "]");
|
||||
if (!!msg) _log(msg);
|
||||
}
|
||||
};
|
||||
|
|
|
|||
Loading…
Reference in a new issue