Browse Source

Implement internationalized error and messages for IVProgAssessment

Lucas de Souza 5 years ago
parent
commit
a8f1353634

+ 3 - 1
i18n/en/error.json

@@ -82,5 +82,7 @@
   "invalid_array_literal_line": "Esperava-se $0 linhas mas encontrou $1.",
   "invalid_array_literal_column_full": "Erro na linha $0: esperava-se $1 colunas mas encontrou $2.",
   "invalid_array_literal_column": "Esperava-se $0 colunas mas encontrou $1.",
-  "exceeded_input_request": "The amount of requests exceeded the amount of available inputs"
+  "exceeded_input_request": "The amount of requests exceeded the amount of available inputs",
+  "test_case_few_reads": "Test case $0: Failed, there are input data remainig!",
+  "test_case_failed": "Test case $0: Failed, inputs:<$1>; expected output:<$2>; output:<$3>"
 }

+ 1 - 1
i18n/en/message.json

@@ -1,3 +1,3 @@
 {
-  
+  "test_case_success": "Test case $0: OK"
 }

+ 3 - 1
i18n/es/error.json

@@ -82,5 +82,7 @@
   "invalid_array_literal_line": "Esperava-se $0 linhas mas encontrou $1.",
   "invalid_array_literal_column_full": "Erro na linha $0: esperava-se $1 colunas mas encontrou $2.",
   "invalid_array_literal_column": "Esperava-se $0 colunas mas encontrou $1.",
-  "exceeded_input_request": "The amount of requests exceeded the amount of available inputs"
+  "exceeded_input_request": "A quantidade de leituras requisitadas execedeu a quantidade de entradas disponíveis.",
+  "test_case_few_reads": "Caso de teste $0: Falhou, ainda restam entradas!",
+  "test_case_failed": "Caso de teste $0: Falhou, entradas:<$1>; saída esperada:<$2>; saída:<$3>"
 }

+ 1 - 1
i18n/es/message.json

@@ -1,3 +1,3 @@
 {
-  
+  "test_case_success": "Caso de teste $0: OK" 
 }

+ 3 - 1
i18n/pt/error.json

@@ -82,5 +82,7 @@
   "invalid_array_literal_line": "Esperava-se $0 linhas mas encontrou $1.",
   "invalid_array_literal_column_full": "Erro na linha $0: esperava-se $1 colunas mas encontrou $2.",
   "invalid_array_literal_column": "Esperava-se $0 colunas mas encontrou $1.",
-  "exceeded_input_request": "A quantidade de leituras requisitadas execedeu a quantidade de entradas disponíveis."
+  "exceeded_input_request": "A quantidade de leituras requisitadas execedeu a quantidade de entradas disponíveis.",
+  "test_case_few_reads": "Caso de teste $0: Falhou, ainda restam entradas!",
+  "test_case_failed": "Caso de teste $0: Falhou, entradas:<$1>; saída esperada:<$2>; saída:<$3>"
 }

+ 1 - 1
i18n/pt/message.json

@@ -1,3 +1,3 @@
 {
-  
+  "test_case_success": "Caso de teste $0: OK" 
 }

+ 17 - 5
js/assessment/ivprogAssessment.js

@@ -3,6 +3,7 @@ import { SemanticAnalyser } from "./../processor/semantic/semanticAnalyser";
 import { IVProgProcessor } from "./../processor/ivprogProcessor";
 import { InputTest } from "./../util/inputTest";
 import { OutputTest } from "./../util/outputTest";
+import { LocalizedStrings } from "../services/localizedStringsService";
 
 export class IVProgAssessment {
 
@@ -46,25 +47,28 @@ export class IVProgAssessment {
     return prog.interpretAST().then( _ => {
       const millis = Date.now() - startTime;
       if (input.inputList.length !== input.index) {
-        outerThis.domConsole.err(`Caso de teste ${name + 1}: Falhou, ainda restam entradas!`);
+        outerThis.showErrorMessage('test_case_few_reads', name+1);
         outerThis.domConsole.info(`Levou ${millis}ms`);
         return Promise.resolve(accumulator + 1 * (input.index/inputList.length));
       } else if (output.list.length < outputList.length) {
-        outerThis.domConsole.err(`Caso de teste ${name + 1}: Falhou <${inputList.join(", ")};${outputList.join(", ")};${output.list.join(", ")}>`);
+        outerThis.showErrorMessage('test_case_failed', name + 1, inputList.join(','),
+          outputList.join(','), output.list.join(','));
         outerThis.domConsole.info(`Levou ${millis}ms`);
         return Promise.resolve(accumulator + 1 * (output.list.length/outputList.length));
       } else if (output.list.length > outputList.length) {
-        outerThis.domConsole.err(`Caso de teste ${name + 1}: Falhou <${inputList.join(", ")};${outputList.join(", ")};${output.list.join(", ")}>`);
+        outerThis.showErrorMessage('test_case_failed', name + 1, inputList.join(','),
+          outputList.join(','), output.list.join(','));
         outerThis.domConsole.info(`Levou ${millis}ms`);
         return Promise.resolve(accumulator + 1 * (outputList.length/output.list.length));
       } else {
         const isOk = outerThis.checkOutput(output.list, outputList);
         if(!isOk) {
-          outerThis.domConsole.err(`Caso de teste ${name + 1}: Falhou <${inputList.join(", ")};${outputList.join(", ")};${output.list.join(", ")}>`);
+          outerThis.showErrorMessage('test_case_failed', name + 1, inputList.join(','),
+            outputList.join(','), output.list.join(','));
           outerThis.domConsole.info(`Levou ${millis}ms`);
           return Promise.resolve(accumulator);
         } else {
-          outerThis.domConsole.info(`Caso de teste ${name + 1}: OK!`);
+          outerThis.showMessage('test_case_success', name + 1);
           outerThis.domConsole.info(`Levou ${millis}ms`);
           return Promise.resolve(accumulator + 1);
         }
@@ -89,4 +93,12 @@ export class IVProgAssessment {
     }
     return true;
   }
+
+  showErrorMessage (errorID, ...args) {
+    this.domConsole.err(LocalizedStrings.getError(errorID, args));
+  }
+
+  showMessage (msgID, ...args) {
+    this.domConsole.info(LocalizedStrings.getMessage(msgID, args));
+  }
 }

+ 1 - 0
js/visualUI/functions.js

@@ -568,6 +568,7 @@ function runCodeAssessment () {
   if(domConsole == null)
     domConsole = new DOMConsole("#ivprog-term");
   $("#ivprog-term").slideDown(500);
+  const testCases = [{input:[1], output:[1]}];
   const runner = new IVProgAssessment(strCode, testCases, domConsole);
 
   runner.runTest().then(grade => {