Permalink
Browse files

Fix multiple answer type and add a test

Test Plan:
Ran tests, answered a problem in equation_of_a_circle_1.

Auditors: eater
  • Loading branch information...
1 parent 6be506a commit 85c0894291a6eb62263167d50206577a374d6723 @spicyj spicyj committed Apr 21, 2013
Showing with 35 additions and 6 deletions.
  1. +0 −1 utils/answer-types.js
  2. +35 −5 utils/test/answer-types.html
View
@@ -611,7 +611,6 @@ Khan.answerTypes = $.extend(Khan.answerTypes, {
// TODO(alpert): Don't think this $.trim is necessary
var correctFloat = parseFloat($.trim(correct));
- options.type = "predicate";
return [
function(guess, maxError) {
return Math.abs(guess - correctFloat) < maxError;
@@ -71,16 +71,27 @@ <h2 id="qunit-userAgent"></h2>
}
function testAnswer(answerData, input, result, description) {
+ $("#solutionarea input").val(input);
+ checkAnswer(answerData, result, description + " [" + input + "]");
+ }
+
+ function testMultipleAnswer(answerData, inputs, result, description) {
+ _.chain($("#solutionarea input")).zip(inputs).each(function(args) {
+ var el = args[0], text = args[1];
+ $(el).val(text);
+ });
+ checkAnswer(
+ answerData, result, description + " [" + inputs.join(", ") + "]");
+ }
+
+ function checkAnswer(answerData, result, description) {
var validator = answerData.validator;
var getAnswer = answerData.answer;
- $("#solutionarea input").val(input);
if (result === "string") { // literally, the string "string"
- strictEqual(typeof validator(getAnswer()), "string",
- description + " [" + input + "]");
+ strictEqual(typeof validator(getAnswer()), "string", description);
} else {
- strictEqual(validator(getAnswer()), result,
- description + " [" + input + "]");
+ strictEqual(validator(getAnswer()), result, description);
}
}
@@ -471,6 +482,25 @@ <h2 id="qunit-userAgent"></h2>
start();
});
+ asyncTest("multiple", 4, function() {
+ var $problem = jQuery("#qunit-fixture .problem").append(
+ "<p class='solution' data-type='multiple'>" +
+ "<span class='sol'>7<\/span>" +
+ "<span class='sol'>1.5<\/span>" +
+ "<\/p>"
+ );
+
+ var answerData = Khan.answerTypes.multiple.setup($("#solutionarea"),
+ $problem.children(".solution"));
+
+ testMultipleAnswer(answerData, ["7", "3/2"], true, "right answer is right");
+ testMultipleAnswer(answerData, ["7", "1.5"], true, "right answer is right");
+ testMultipleAnswer(answerData, ["3/2", "7"], false, "wrong answer is wrong");
+ testMultipleAnswer(answerData, ["7", "6/4"], "string", "unsimplified right answer provides a message");
+
+ start();
+ });
+
asyncTest("radio answerability", 8, function() {
var $problem = jQuery("#qunit-fixture .problem").append(
"<p class='solution'><code>6<\/code><\/p>" +

0 comments on commit 85c0894

Please sign in to comment.