Explorar el Código

Implement permanent console

Implement Assessment time and proportional grade based on missing i/o
Lucas de Souza hace 6 años
padre
commit
0253252734
Se han modificado 3 ficheros con 28 adiciones y 35 borrados
  1. 23 27
      js/assessment/ivprogAssessment.js
  2. 1 1
      js/io/domConsole.js
  3. 4 7
      js/visualUI/functions.js

+ 23 - 27
js/assessment/ivprogAssessment.js

@@ -20,25 +20,13 @@ export class IVProgAssessment {
         const parser = IVProgParser.createParser(outerRef.textCode);
         const semantic = new SemanticAnalyser(parser.parseTree());
         const validTree = semantic.analyseTree();
-        const fun = outerRef.partialBindTestCase(outerRef.evaluateTestCase, new IVProgProcessor(validTree));
         // loop test cases and show messages through domconsole
         const tests = outerRef.testCases.map( (t, name) => {
           return outerRef.evaluateTestCase(new IVProgProcessor(validTree), t.input, t.output, name);
         });
         Promise.all(tests).then(results => {
-          const count = results.reduce((p, n) => {
-            if(n) {
-              return p + 1;
-            } else {
-              return p + 0;
-            }
-          },0);
-          const failed = outerRef.testCases.length - count;
-          if(failed === 0) {
-            resolve(1);
-          } else {
-            resolve(count / outerRef.testCases.length);
-          }
+          const count = results.reduce((lastValue, nextValue) =>  lastValue + nextValue, 0);
+          resolve(count / outerRef.testCases.length);
         }).catch(err => {
           outerRef.domConsole.err("Erro durante a execução do programa");// try and show error messages through domconsole
           outerRef.domConsole.err(err.message);
@@ -59,29 +47,37 @@ export class IVProgAssessment {
       const output = new OutputTest();
       prog.registerInput(input);
       prog.registerOutput(output);
+      const startTime = Date.now()
       prog.interpretAST().then( _ => {
-        if (input.inputList.length !== input.index ||
-          output.list.length !== outputList.length) {
-          outerThis.domConsole.err(`Caso de teste ${name} falhou!`);
-          resolve(false);
+        const millis = Date.now() - startTime;
+        if (input.inputList.length !== input.index) {
+          outerThis.domConsole.err(`Caso de teste ${name + 1}: Falhou, ainda restam entradas!`);
+          outerThis.domConsole.err(`Levou ${millis}ms`);
+          resolve(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.domConsole.err(`Levou ${millis}ms`);
+          resolve(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.domConsole.err(`Levou ${millis}ms`);
+          resolve(1 * (outputList.length/output.list.length));
         } else {
           const isOk = outerThis.checkOutput(output.list, outputList);
           if(!isOk) {
-            outerThis.domConsole.err(`Caso de teste ${name} falhou!`);
-            resolve(false);
+            outerThis.domConsole.err(`Caso de teste ${name + 1}: Falhou <${inputList.join(", ")};${outputList.join(", ")};${output.list.join(", ")}>`);
+            outerThis.domConsole.err(`Levou ${millis}ms`);
+            resolve(0);
           } else {
-            outerThis.domConsole.info(`Caso de teste ${name} passou!`);
-            resolve(true);
+            outerThis.domConsole.info(`Caso de teste ${name + 1}: OK!`);
+            outerThis.domConsole.err(`Levou ${millis}ms`);
+            resolve(1);
           }
         }
-      }).catch( err => reject(err));
+      }).catch( _ => resolve(0));
     })
   }
 
-  partialBindTestCase (fun, param) {
-    return (i, o) => fun(param, i, o);
-  }
-
   checkOutput (aList, bList) {
     for (let i = 0; i < aList.length; i++) {
       const outValue = aList[i];

+ 1 - 1
js/io/domConsole.js

@@ -16,7 +16,7 @@ export class DOMConsole {
 
   constructor (elementID) {
     this.input = null;
-    this.needInput = true;
+    this.needInput = false;
     this.anyKey = false;
     this.parent = $(elementID);
     this.setup();

+ 4 - 7
js/visualUI/functions.js

@@ -308,12 +308,11 @@ function runCodeAssessment () {
   if (strCode == null) {
     return;
   }
-  domConsole = new DOMConsole("#ivprog-term");
+  if(domConsole == null)
+    domConsole = new DOMConsole("#ivprog-term");
   $("#ivprog-term").slideDown(500);
   const runner = new IVProgAssessment(strCode, testCases, domConsole);
   runner.runTest().then(grade => studentGrade = grade).catch( err => domConsole.err(err.message));
-  
-  waitToCloseConsole()
 }
 
 function runCode () {
@@ -321,7 +320,8 @@ function runCode () {
   if (strCode == null) {
     return;
   }
-  domConsole = new DOMConsole("#ivprog-term");
+  if(domConsole == null)
+    domConsole = new DOMConsole("#ivprog-term");
   $("#ivprog-term").slideDown(500);
   try {
     const parser = IVProgParser.createParser(strCode);
@@ -333,14 +333,11 @@ function runCode () {
     
     proc.interpretAST().then( _ => {
       domConsole.info("Programa executado com sucesso!");
-      waitToCloseConsole();
     }).catch(err => {
       domConsole.err(err.message);
-      waitToCloseConsole();
     }) 
   } catch (error) {
     domConsole.err(error.message);
-    waitToCloseConsole();
     console.log(error);
   }