Skip to content

Commit

Permalink
quicktest: ignore min/max errors unless they're simple constants
Browse files Browse the repository at this point in the history
  • Loading branch information
dfabulich committed Apr 30, 2017
1 parent 841f827 commit 7e55b08
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
2 changes: 2 additions & 0 deletions editor/embeddable-autotester.js
Expand Up @@ -21,6 +21,8 @@ function autotester(sceneText, nav, sceneName, extraLabels) {
}
}

Scene.prototype.quicktest = true;

Scene.prototype.finish = function test_finish(buttonName) {
this.paragraph();
this.finished = true;
Expand Down
16 changes: 14 additions & 2 deletions web/scene.js
Expand Up @@ -1728,6 +1728,13 @@ Scene.prototype.input_number = function input_number(data) {
throw new Error(this.lineMsg() + "Non-existent variable '"+variable+"'");
}

var simpleConstants;
if (stack.length == 2 && stack[0].name == "NUMBER" && stack[1].name == "NUMBER") {
simpleConstants = true;
} else {
simpleConstants = false;
}

if (!stack.length) throw new Error(this.lineMsg() + "Invalid input_number statement, expected three args: varname min max");
var minimum = this.evaluateValueToken(stack.shift(), stack);
if (isNaN(minimum*1)) throw new Error(this.lineMsg() + "Invalid minimum, not numeric: " + minimum);
Expand All @@ -1737,7 +1744,12 @@ Scene.prototype.input_number = function input_number(data) {
if (stack.length) throw new Error(this.lineMsg() + "Invalid input_number statement, expected three args: varname min max");
if (isNaN(maximum*1)) throw new Error(this.lineMsg() + "Invalid maximum, not numeric: " + maximum);

if (parseFloat(minimum) > parseFloat(maximum)) throw new Error(this.lineMsg() + "Minimum " + minimum+ " should not be greater than maximum " + maximum);
// in quicktest, min and max can get mixed up as the interpreter "cheats" on if statements
// so quicktest will ignore min/max errors unless they're simple constants e.g. *input_number x 6 4
var checkMinMax = !this.quicktest || simpleConstants;
if (checkMinMax && parseFloat(minimum) > parseFloat(maximum)) {
throw new Error(this.lineMsg() + "Minimum " + minimum+ " should not be greater than maximum " + maximum);
}

function isInt(x) {
var y=parseInt(x,10);
Expand Down Expand Up @@ -1766,7 +1778,7 @@ Scene.prototype.input_number = function input_number(data) {
asyncAlert("Please use a number greater than or equal to " + minimum);
return;
}
if (numValue > maximum * 1) {
if (numValue > maximum * 1 && !this.quicktest) {
asyncAlert("Please use a number less than or equal to " + maximum);
return;
}
Expand Down

0 comments on commit 7e55b08

Please sign in to comment.