assert error change for error thrown, formatted getScript, added default epsilon for assert near
This commit is contained in:
parent
61dfe2de65
commit
8805521ce2
1 changed files with 21 additions and 21 deletions
22
js/utils.js
22
js/utils.js
|
@ -418,23 +418,23 @@ function capitalizeFirst(str) {
|
|||
* If we ever want to write something that needs to import other js files
|
||||
*/
|
||||
const getScript = url => new Promise((resolve, reject) => {
|
||||
const script = document.createElement('script')
|
||||
script.src = url
|
||||
script.async = true
|
||||
const script = document.createElement('script');
|
||||
script.src = url;
|
||||
script.async = true;
|
||||
|
||||
script.onerror = reject
|
||||
script.onerror = reject;
|
||||
|
||||
script.onload = script.onreadystatechange = function () {
|
||||
const loadState = this.readyState
|
||||
const loadState = this.readyState;
|
||||
|
||||
if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
|
||||
|
||||
script.onload = script.onreadystatechange = null
|
||||
script.onload = script.onreadystatechange = null;
|
||||
|
||||
resolve()
|
||||
resolve();
|
||||
}
|
||||
|
||||
document.head.appendChild(script)
|
||||
document.head.appendChild(script);
|
||||
})
|
||||
|
||||
/*
|
||||
|
@ -479,10 +479,10 @@ function assert_equals(arg1, arg2, msg) {
|
|||
*
|
||||
* @param {*} arg1 - first argument to compare.
|
||||
* @param {*} arg2 - second argument to compare.
|
||||
* @param {Number} epsilon - the margin of error (<= del difference is ok).
|
||||
* @param {Number} epsilon - the margin of error (<= del difference is ok). Defaults to -1E5.
|
||||
* @param {String} msg - the error message to throw.
|
||||
*/
|
||||
function assert_near(arg1, arg2, epsilon, msg) {
|
||||
function assert_near(arg1, arg2, epsilon = 1E-5, msg) {
|
||||
if (Math.abs(arg1 - arg2) > epsilon) {
|
||||
throw new Error(msg ? msg : "Assert Near failed. " + arg1 + " is not within " + epsilon + " of " + arg2 + ".");
|
||||
}
|
||||
|
@ -518,8 +518,8 @@ function assert_null(arg, msg) {
|
|||
function assert_error(func_binding, msg) {
|
||||
try {
|
||||
func_binding();
|
||||
console.trace(msg ? msg : "Function didn't throw an error.");
|
||||
} catch (err) {
|
||||
return;
|
||||
}
|
||||
throw new Error(msg ? msg : "Function didn't throw an error.");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue