|
@@ -6,6 +6,7 @@ import { OutputTest } from "./../util/outputTest";
|
|
import { DOMConsole} from "./../io/domConsole";
|
|
import { DOMConsole} from "./../io/domConsole";
|
|
import * as LocalizedStringsService from "../services/localizedStringsService";
|
|
import * as LocalizedStringsService from "../services/localizedStringsService";
|
|
import { Config } from "../util/config";
|
|
import { Config } from "../util/config";
|
|
|
|
+import { OutputMatching } from './output_matching/output_matching';
|
|
|
|
|
|
|
|
|
|
const LocalizedStrings = LocalizedStringsService.getInstance();
|
|
const LocalizedStrings = LocalizedStringsService.getInstance();
|
|
@@ -26,19 +27,49 @@ export class IVProgAssessment {
|
|
try {
|
|
try {
|
|
// loop test cases and show messages through domconsole
|
|
// loop test cases and show messages through domconsole
|
|
const partialTests = this.testCases.map( (t, name) => {
|
|
const partialTests = this.testCases.map( (t, name) => {
|
|
- return outerRef.partialEvaluateTestCase(new IVProgProcessor(outerRef.ast_code), t.input, t.output, name);
|
|
|
|
|
|
+ return new OutputMatching(new IVProgProcessor(outerRef.ast_code), t.input, t.output, name);
|
|
});
|
|
});
|
|
- const testResult = partialTests.reduce((acc, curr) => acc.then(curr), Promise.resolve(0));
|
|
|
|
- return testResult.then(function (total) {
|
|
|
|
- const grade = total / outerRef.testCases.length;
|
|
|
|
|
|
+ const testResult = partialTests.map(om => om.eval());
|
|
|
|
+ return Promise.all(testResult).then(results => {
|
|
|
|
+ let grade = 0;
|
|
|
|
+ for(let i = 0; i < results.length; ++i) {
|
|
|
|
+ const result = results[i];
|
|
|
|
+ grade += result.grade;
|
|
|
|
+ if(result.grade == 1) {
|
|
|
|
+ outerRef.writeToConsole(DOMConsole.INFO, StringTypes.MESSAGE,'test_case_success',
|
|
|
|
+ result.name+1, result.generateOutput());
|
|
|
|
+ } else if (result.status == 1) {
|
|
|
|
+ outerRef.writeToConsole(DOMConsole.ERR, StringTypes.ERROR,'test_case_failed_exception',
|
|
|
|
+ result.name+1,
|
|
|
|
+ result.error_msg,
|
|
|
|
+ result.generateOutput());
|
|
|
|
+ } else {
|
|
|
|
+ const inputs = result.inputs.map(input => input.value);
|
|
|
|
+ const outputs = result.results;
|
|
|
|
+ const expected_output = outputs.map(r => r.expected || '').filter( str => (''+str).length > 0);
|
|
|
|
+ const generated_output = outputs.map(r => r.generated || '').filter( str => (''+str).length > 0);
|
|
|
|
+ outerRef.writeToConsole(DOMConsole.ERR, StringTypes.ERROR,'test_case_failed',
|
|
|
|
+ result.name+1,
|
|
|
|
+ inputs.join(LocalizedStrings.getUI('text_join_assessment_outputs')),
|
|
|
|
+ expected_output.join(LocalizedStrings.getUI('text_join_assessment_outputs')),
|
|
|
|
+ generated_output.join(LocalizedStrings.getUI('text_join_assessment_outputs')),
|
|
|
|
+ result.generateOutput());
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ grade /= results.length;
|
|
const channel = grade == 1 ? DOMConsole.INFO : DOMConsole.ERR;
|
|
const channel = grade == 1 ? DOMConsole.INFO : DOMConsole.ERR;
|
|
outerRef.writeToConsole(channel, StringTypes.MESSAGE, "test_suite_grade", (grade * 100).toFixed(2));
|
|
outerRef.writeToConsole(channel, StringTypes.MESSAGE, "test_suite_grade", (grade * 100).toFixed(2));
|
|
- return Promise.resolve(grade)
|
|
|
|
- }).catch(err => {
|
|
|
|
- outerRef.domConsole.err("Erro inesperado durante o cálculo da nota.");// try and show error messages through domconsole
|
|
|
|
- outerRef.domConsole.err(err.message);
|
|
|
|
- return Promise.resolve(0);
|
|
|
|
});
|
|
});
|
|
|
|
+ // return testResult.then(function (total) {
|
|
|
|
+ // const grade = total / outerRef.testCases.length;
|
|
|
|
+ // const channel = grade == 1 ? DOMConsole.INFO : DOMConsole.ERR;
|
|
|
|
+ // outerRef.writeToConsole(channel, StringTypes.MESSAGE, "test_suite_grade", (grade * 100).toFixed(2));
|
|
|
|
+ // return Promise.resolve(grade)
|
|
|
|
+ // }).catch(err => {
|
|
|
|
+ // outerRef.domConsole.err("Erro inesperado durante o cálculo da nota.");// try and show error messages through domconsole
|
|
|
|
+ // outerRef.domConsole.err(err.message);
|
|
|
|
+ // return Promise.resolve(0);
|
|
|
|
+ // });
|
|
} catch (error) {
|
|
} catch (error) {
|
|
outerRef.domConsole.err("Erro inesperado durante a execução do programa");// try and show error messages through domconsole
|
|
outerRef.domConsole.err("Erro inesperado durante a execução do programa");// try and show error messages through domconsole
|
|
outerRef.domConsole.err(error.message);
|
|
outerRef.domConsole.err(error.message);
|