Browse Source

Implement whitespace trim on string outputs during automatic assessment for both expected and generated outputs

Lucas de Souza 4 years ago
parent
commit
70d9767b34

+ 3 - 2
js/assessment/output_matching/assessment_result.js

@@ -198,7 +198,7 @@ export class OutputAssessmentResult {
 
     const g_string = result.generated || "";
     const e_string = result.expected || "";
-    console.log("generated: ", g_string,"expected: ", e_string);
+    // console.log("generated: ", g_string,"expected: ", e_string);
     let g_string_tmpl = g_string;
     let e_string_tmpl = e_string;
     if(result.generated == null) {
@@ -215,6 +215,7 @@ export class OutputAssessmentResult {
       template = template.replace(":class-result:", 'assessment-string-result');
     } else {
       const diff = StringDiff(g_string, e_string);
+      // console.log(diff);
       const diff_vec = diff.map(part => this.getDiffStringStyle(part[1], part[0]), this);
       const diff_string = diff_vec.reduce((prev, actual) => prev + actual, "");
       template = template.replace("$2", "<span class='assessment-failed-case'>✗</span>" + diff_string);
@@ -226,7 +227,7 @@ export class OutputAssessmentResult {
   getDiffStringStyle (text, action) {
     const template = "<span class='$0'>$1</span>"
     // Fix missing whitespace when its a single element
-    text = text.replace(/\s/g,"&#x0020;");
+    text = text.replace(/\s/g,"&#160;");
     switch(action) {
       case StringDiff.INSERT:
         return template.replace("$0", "stringdiff-insert").replace("$1", text);

+ 2 - 2
js/assessment/output_matching/output_matching.js

@@ -121,8 +121,8 @@ export class OutputMatching {
 
   checkStrings (g_output, e_ouput) {
     const assessmentList = []
-    let e_output_clean = e_ouput;
-    let g_output_clean = g_output;
+    let e_output_clean = e_ouput.trim();
+    let g_output_clean = g_output.trim();
     if (OutputMatching.NUM_IN_STRING_REGEX.test(e_ouput)) {
       const expected_numbers = e_ouput.match(OutputMatching.NUM_IN_STRING_REGEX);
       const generated_numbers = g_output.match(OutputMatching.NUM_IN_STRING_REGEX) || [];

+ 4 - 4
js/processor/lib/io.js

@@ -30,13 +30,13 @@ export function createInputFun () {
       let result = null;
       try {
         if (typeToConvert.isCompatible(Types.INTEGER)) {
-          result = toInt(text).trunc();
+          result = toInt(text.trim()).trunc();
           type = Types.INTEGER;
         } else if (typeToConvert.isCompatible(Types.REAL)) {
-          result = toReal(text)
+          result = toReal(text.trim())
           type = Types.REAL;
         } else if (typeToConvert.isCompatible(Types.BOOLEAN)) {
-          result = toBool(text)
+          result = toBool(text.trim())
           type = Types.BOOLEAN;
         } else if (typeToConvert.isCompatible(Types.STRING)) {
           result = toString(text)
@@ -71,4 +71,4 @@ export function createInputFun () {
     [new Commands.FormalParameter(Types.ALL, 'p1', true)],
     block);
   return func;
-}
+}