Преглед изворни кода

Merge branch 'remove-assessment-trim' of LInE/ivprog into master

Lucas de Souza пре 5 година
родитељ
комит
7137d76251

+ 5 - 2
css/ivprog-assessment.css

@@ -66,7 +66,10 @@ table td { font-size: 14pt;}
 }
 .assessment-string-expected, .assessment-string-generated, .assessment-string-diff {text-align: left;}
 p.assessment-failed-execution {padding-left: 1rem;}
-.assessment-failed-case {color:#FF1212}
+.assessment-failed-case {
+  color:#FF1212;
+  padding-right: 1rem;
+}
 .assessment-input-unread {color: #d02929}
 .assessment-number-result-failed, .assessment-bool-result-failed {color: #d02929}
 .assessment-number-result, .assessment-bool-result, .assessment-string-result {color: #22a222}
@@ -115,4 +118,4 @@ p.assessment-failed-execution {padding-left: 1rem;}
 .assessment-empty-output {
   height: 1.5rem;
   width: 1.5rem;
-}
+}

+ 2 - 2
i18n/message.csv

@@ -4,9 +4,9 @@ test_case_duration,Levou $0ms,Took $0ms," "
 test_suite_grade,A sua solução alcançou $0% da nota.,Your solution scored $0% of the grade.," "
 awaiting_input_message,O seu programa está em execução e aguardando uma entrada! Digite algo e pressione ENTER...,Your program is running and awaiting for an input. Type something and press ENTER…," "
 assessment-empty-expected-tooltip,A saída gerada foi além do esperado,The generated output was beyond the amount expected," "
-assessment-empty-generated-tooltip,O programa não gerou saídas suficientes,The program did not generated enough outputs," "
+assessment-empty-generated-tooltip,O programa não gerou saídas suficientes,The program did not generate enough outputs," "
 testcase_autogen_unused_input,O caso de teste $0 possui mais entradas do que as leituras feitas no programa.,The test case $0 has more inputs than output than the number of reads present in the algorithm.," "
 testcase_autogen_empty,O caso de teste $0 não gerou qualquer saída.,The test case $0 did not generate any output.," "
 success_execution,Programa executado com sucesso!,Program executed successfully!,
 aborted_execution,A execução do programa foi interrompida!,Program execution was aborted!,
-unexpected_execution_error,Erro inesperado durante a execução do programa.,Unexpected error during program execution.,
+unexpected_execution_error,Erro inesperado durante a execução do programa.,Unexpected error during program execution.,

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

@@ -152,7 +152,7 @@ export class OutputAssessmentResult {
   }
 
   formatNumber (result) {
-    const result_class = result.grade == 1 ? 'assessment-number-result' : 'assessment-number-result-failed'; 
+    const result_class = result.grade == 1 ? 'assessment-number-result' : 'assessment-number-result-failed';
     let template = this.formatOutput('assessment-number-expected',
       'assessment-number-generated', result_class, result);
     return template
@@ -198,8 +198,18 @@ export class OutputAssessmentResult {
 
     const g_string = result.generated || "";
     const e_string = result.expected || "";
-    template = template.replace("$0", result.expected);
-    template = template.replace("$1", result.generated);
+    console.log("generated: ", g_string,"expected: ", e_string);
+    let g_string_tmpl = g_string;
+    let e_string_tmpl = e_string;
+    if(result.generated == null) {
+      g_string_tmpl = OutputAssessmentResult.EMPTY_OUTPUT_TEMPLATE.replace('$0',
+        LocalizedStrings.getMessage('assessment-empty-generated-tooltip'));
+    } else if (result.expected == null) {
+     e_string_tmpl = OutputAssessmentResult.EMPTY_OUTPUT_TEMPLATE.replace('$0',
+        LocalizedStrings.getMessage('assessment-empty-expected-tooltip'));
+    }
+    template = template.replace("$0", e_string_tmpl);
+    template = template.replace("$1", g_string_tmpl);
     if(result.grade == 1) {
       template = template.replace("$2", "✓");
       template = template.replace(":class-result:", 'assessment-string-result');
@@ -215,6 +225,8 @@ 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;");
     switch(action) {
       case StringDiff.INSERT:
         return template.replace("$0", "stringdiff-insert").replace("$1", text);

+ 9 - 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;
@@ -57,6 +57,7 @@ export class OutputMatching {
         return this.outputMatch(g_out, this.expected_output[i]);
       }, this);
       if(this.expected_output.length > gen_output.list.length) {
+        console.log("Saída insuficientes!",this.expected_output.length,gen_output.list.length);
         for(let i = gen_output.list.length; i < this.expected_output.length; ++i) {
           const e_out = this.expected_output[i];
           result.push(new OutputResult.OutputMatchResult(e_out, null, 0, this.getPotentialOutputType(e_out)));
@@ -135,11 +136,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 +157,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 +170,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);
   }

+ 6 - 6
js/io/domConsole.js

@@ -130,7 +130,7 @@ export class DOMConsole {
   _setupCursor () {
     this.inputCMD.addEventListener('click', this.blinkCaretAndFocus.bind(this));
     //this.inputCMD.click();
-    
+
     this.input.addEventListener('keyup', this.updateSpanText.bind(this));
     this.input.addEventListener('blur', this.stopBlinkCaret.bind(this));
   }
@@ -217,7 +217,7 @@ export class DOMConsole {
 
   getOutputText (text) {
     if(text.trim().length == 0) {
-      text = "&nbsp;";
+      text = text.replace(/\s/g, "&#x0020;");
     }
     return `<span>${text}</span>`;
   }
@@ -328,8 +328,8 @@ export class DOMConsole {
   sendOutput (text) {
     const output = ""+text;
     output.split("\n").forEach(t => {
-      t = t.replace(/\t/g,'&nbsp;&nbsp;');
-      t = t.replace(/\s/g,"&nbsp;");
+      t = t.replace(/\t/g,'&#x0020;&#x0020;');
+      t = t.replace(/\s/g,"&#x0020;");
       this.write(t)
     });
   }
@@ -367,7 +367,7 @@ export class DOMConsole {
     this.info(LocalizedStrings.getMessage('awaiting_input_message'));
     this.inputCMD.click();
   }
-  
+
   scheduleNotify () {
     this.idleInterval = window.setInterval(this.notifyIdle.bind(this), Config.idle_input_interval);
   }
@@ -384,4 +384,4 @@ export class DOMConsole {
     this.hideInput();
     this.anyKey = false;
   }
-}
+}

+ 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 {
     });
   }
 
-}
+}