ソースを参照

Remove trim from string output matching

Lucas Mendonça 5 年 前
コミット
5a157950c2

+ 8 - 8
js/assessment/output_matching/output_matching.js

@@ -14,7 +14,7 @@ export class OutputMatching {
 
   static get NUM_REGEX () {
     return /^[+-]?([0-9]+([.][0-9]*)?(e[+-]?[0-9]+)?)$/;
-  } 
+  }
 
   static get NUM_IN_STRING_REGEX () {
     return /[+-]?([0-9]+([.][0-9]*)?(e[+-]?[0-9]+)?)/g;
@@ -29,7 +29,7 @@ export class OutputMatching {
     const str = `(${LocalizedStrings.getUI("logic_value_true")}|${LocalizedStrings.getUI("logic_value_false")})`;
     return new RegExp(str, 'g');
   }
-  
+
   constructor (program, input_list, expected_output, test_name) {
     this.program = program;
     this.name = test_name;
@@ -135,11 +135,11 @@ export class OutputMatching {
           result.push(OutputResult.createNumberResult(expected_numbers[i], null, 0));
         }
       }
-      e_output_clean = e_output_clean.replace(OutputMatching.NUM_IN_STRING_REGEX, '').trim();
-      g_output_clean = g_output_clean.replace(OutputMatching.NUM_IN_STRING_REGEX, '').trim();
+      e_output_clean = e_output_clean.replace(OutputMatching.NUM_IN_STRING_REGEX, '');
+      g_output_clean = g_output_clean.replace(OutputMatching.NUM_IN_STRING_REGEX, '');
       const numberGrade = result.reduce((prev, r) => prev + r.grade, 0) / result.length;
       assessmentList.push(numberGrade);
-    } 
+    }
     if(OutputMatching.BOOLEAN_IN_STRING_REGEX.test(e_ouput)) {
       const expected_bools = e_ouput.match(OutputMatching.BOOLEAN_IN_STRING_REGEX);
       const generated_bools = g_output.match(OutputMatching.BOOLEAN_IN_STRING_REGEX) || [];
@@ -156,8 +156,8 @@ export class OutputMatching {
           result.push(OutputResult.createBoolResult(expected_bools[i], null, 0));
         }
       }
-      e_output_clean = e_output_clean.replace(OutputMatching.BOOLEAN_IN_STRING_REGEX, '').trim();
-      g_output_clean = g_output_clean.replace(OutputMatching.BOOLEAN_IN_STRING_REGEX, '').trim();
+      e_output_clean = e_output_clean.replace(OutputMatching.BOOLEAN_IN_STRING_REGEX, '');
+      g_output_clean = g_output_clean.replace(OutputMatching.BOOLEAN_IN_STRING_REGEX, '');
       const boolGrade = result.reduce((prev, r) => prev + r.grade, 0) / result.length;
       assessmentList.push(boolGrade);
     }
@@ -169,7 +169,7 @@ export class OutputMatching {
     const finalGrade = 1 * (gradeDiff/assessment_size + gradeAcc);
     return OutputResult.createStringResult(e_ouput, g_output, finalGrade);
   }
-  
+
   getErrorMessage (errorID, ...args) {
     return LocalizedStrings.getError(errorID, args);
   }

+ 34 - 34
js/processor/ivprogProcessor.js

@@ -148,11 +148,11 @@ export class IVProgProcessor {
       }
       run_lambda();
     });
-    
+
   }
 
   associateParameters (formal_params, effective_params, caller_store, callee_store) {
-    const funcName = callee_store.name === IVProgProcessor.MAIN_INTERNAL_ID ? 
+    const funcName = callee_store.name === IVProgProcessor.MAIN_INTERNAL_ID ?
       LanguageDefinedFunction.getMainFunctionName() : callee_store.name;
 
     if (formal_params.length != effective_params.length) {
@@ -261,7 +261,7 @@ export class IVProgProcessor {
         } else if (cmd instanceof Commands.Switch) {
           return resolve(this.executeSwitch(store, cmd));
         } else if (cmd instanceof Expressions.FunctionCall) {
-          return resolve(this.executeFunctionCall(store, cmd));     
+          return resolve(this.executeFunctionCall(store, cmd));
         } else if (cmd instanceof Commands.SysCall) {
           return resolve(this.executeSysCall(store, cmd));
         } else {
@@ -297,7 +297,7 @@ export class IVProgProcessor {
       .then(sto => {
         sto.destroy();
         if(!Types.VOID.isCompatible(func.returnType) && sto.mode !== Modes.RETURN) {
-          const funcName = func.name === IVProgProcessor.MAIN_INTERNAL_ID ? 
+          const funcName = func.name === IVProgProcessor.MAIN_INTERNAL_ID ?
             LanguageDefinedFunction.getMainFunctionName() : func.name;
           return Promise.reject(ProcessorErrorFactory.function_no_return(funcName));
         } else {
@@ -342,9 +342,9 @@ export class IVProgProcessor {
   }
 
   /**
-   * 
-   * @param {Store} store 
-   * @param {Commands.For} cmd 
+   *
+   * @param {Store} store
+   * @param {Commands.For} cmd
    */
   executeFor (store, cmd) {
     //BEGIN for -> while rewrite
@@ -358,9 +358,9 @@ export class IVProgProcessor {
       expression_tuple.push(this.evaluateExpression(store, new Expressions.InfixApp(Operators.GE, cmd.for_pass, new Expressions.IntLiteral(toInt(0)))));
       expression_tuple.push(Promise.resolve(null));
     }
-    
+
     return Promise.all(expression_tuple).then (results => {
-      console.log(results);
+      // console.log(results);
       let is_forward = true;
       let is_end_gt_init = undefined;
       let condition = null;
@@ -373,13 +373,13 @@ export class IVProgProcessor {
       }
 
       if(is_end_gt_init == null) {
-        console.log("pass is not null and is forward? ", is_forward);
+        // console.log("pass is not null and is forward? ", is_forward);
         if(is_forward) {
           condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
         } else {
           condition = new Expressions.InfixApp(Operators.GE, cmd.for_id, cmd.for_to);
         }
-        console.log("Cond", condition);
+        // console.log("Cond", condition);
       } else if(is_end_gt_init) {
         pass_value = new Expressions.IntLiteral(toInt(1));
         condition = new Expressions.InfixApp(Operators.LE, cmd.for_id, cmd.for_to);
@@ -454,7 +454,7 @@ export class IVProgProcessor {
           return Promise.reject(ProcessorErrorFactory.loop_condition_type_full(cmd.expression.toString(), cmd.sourceInfo));
         }
       })
-      
+
     } catch (error) {
       return Promise.reject(error);
     }
@@ -487,13 +487,13 @@ export class IVProgProcessor {
 
   executeReturn (store, cmd) {
     try {
-      const funcName = store.name === IVProgProcessor.MAIN_INTERNAL_ID ? 
+      const funcName = store.name === IVProgProcessor.MAIN_INTERNAL_ID ?
         LanguageDefinedFunction.getMainFunctionName() : store.name;
       // console.log(funcName,  store.name === IVProgProcessor.MAIN_INTERNAL_ID);
       const func = this.findFunction(store.name);
       const funcType = func.returnType;
       const $value = this.evaluateExpression(store, cmd.expression);
-      
+
       return $value.then(value => {
 
         let real_value = value;
@@ -559,11 +559,11 @@ export class IVProgProcessor {
               return Promise.reject(ProcessorErrorFactory.invalid_vector_assignment_full(cmd.id, inStore.lines, exp, realValue.lines, cmd.sourceInfo));
             } else {
               return Promise.reject(ProcessorErrorFactory.invalid_matrix_assignment_full(cmd.id, inStore.lines, inStore.columns, exp, realValue.lines, realValue.columns, cmd.sourceInfo));
-            }            
+            }
           }
         }
-        
-        store.updateStore(cmd.id, realValue) 
+
+        store.updateStore(cmd.id, realValue)
         return store;
       });
     } catch (error) {
@@ -646,9 +646,9 @@ export class IVProgProcessor {
   }
 
   /**
-   * 
-   * @param {Store} store 
-   * @param {Commands.Declaration} cmd 
+   *
+   * @param {Store} store
+   * @param {Commands.Declaration} cmd
    */
   executeDeclaration (store, cmd) {
     try {
@@ -689,9 +689,9 @@ export class IVProgProcessor {
   }
 
   /**
-   * 
-   * @param {Store} store 
-   * @param {Commands.ArrayDeclaration} cmd 
+   *
+   * @param {Store} store
+   * @param {Commands.ArrayDeclaration} cmd
    */
   executeArrayDeclaration (store, cmd) {
     const $lines = this.evaluateExpression(store, cmd.lines);
@@ -772,7 +772,7 @@ export class IVProgProcessor {
         expression_lambda();
       }
     });
-    
+
   }
 
   evaluateFunctionCall (store, exp) {
@@ -800,10 +800,10 @@ export class IVProgProcessor {
   }
 
   /**
-   * 
-   * @param {Store} store 
-   * @param {Expressions.ArrayLiteral} exp 
-   * @param {ArrayType} type 
+   *
+   * @param {Store} store
+   * @param {Expressions.ArrayLiteral} exp
+   * @param {ArrayType} type
    */
   evaluateArrayLiteral (store, exp, type, lines, columns) {
     if(!exp.isVector) {
@@ -827,8 +827,8 @@ export class IVProgProcessor {
 
   /**
    * Evalautes a list of literals and expression composing the vector
-   * @param {Store} store 
-   * @param {Expressions.ArrayLiteral} exps 
+   * @param {Store} store
+   * @param {Expressions.ArrayLiteral} exps
    * @param {ArrayType} type
    * @param {number} n_elements
    * @returns {Promise<StoreValue[]>} store object list
@@ -859,8 +859,8 @@ export class IVProgProcessor {
 
   /**
    * Evaluates a list of array literals composing the matrix
-   * @param {Store} store 
-   * @param {Expressions.ArrayLiteral} exps 
+   * @param {Store} store
+   * @param {Expressions.ArrayLiteral} exps
    * @param {ArrayType} type
    * @returns {Promise<StoreValue[]>[]}
    */
@@ -1022,7 +1022,7 @@ export class IVProgProcessor {
           }
           result = leftValue.modulo(rightValue);
           return new StoreValue(resultType, (result));
-        }          
+        }
         case Operators.GT.ord: {
           let leftValue = left.get();
           let rightValue = right.get();
@@ -1123,4 +1123,4 @@ export class IVProgProcessor {
     });
   }
 
-}
+}