1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- import line_i18n from "line-i18n";
- import { IVProgProcessor } from "./../processor/ivprogProcessor";
- import { DOMConsole } from "./../io/domConsole";
- import { OutputMatching } from "./output_matching/output_matching";
- import { Config } from "../util/config";
- import { Assessment } from "./assessment";
- const StringTypes = line_i18n.StringTypes;
- export class IVProgAssessment extends Assessment {
- constructor (ast_code, testCases, domConsole) {
- super(ast_code, testCases, domConsole);
- }
- runTest () {
- try {
- // loop test cases and show messages through domconsole
- const partialTests = this.testCases.map((t, name) => {
- return new OutputMatching(
- new IVProgProcessor(this.ast_code),
- t.input,
- t.output,
- name,
- t.tag
- );
- });
- const testResult = partialTests.map((om) => om.eval());
- return Promise.all(testResult).then((results) => {
- let grade = 0;
- for (let i = 0; i < results.length; i += 1) {
- const result = results[i];
- grade += result.grade;
- if (result.grade == 1) {
- this.writeToConsole(
- DOMConsole.INFO,
- StringTypes.MESSAGE,
- "test_case_success",
- result.name + 1,
- result.generateOutput()
- );
- } else if (result.status == 1) {
- this.writeToConsole(
- DOMConsole.ERR,
- StringTypes.ERROR,
- "test_case_failed_exception",
- result.name + 1,
- result.error_msg,
- result.generateOutput()
- );
- } else {
- this.writeToConsole(
- DOMConsole.ERR,
- StringTypes.ERROR,
- "test_case_failed",
- result.name + 1,
- result.generateOutput()
- );
- }
- }
- grade /= results.length;
- const channel = grade == 1 ? DOMConsole.INFO : DOMConsole.ERR;
- this.writeToConsole(
- channel,
- StringTypes.MESSAGE,
- "test_suite_grade",
- (grade * 100).toFixed(2)
- );
- return grade;
- });
- // return testResult.then(function (total) {
- // const grade = total / this.testCases.length;
- // const channel = grade == 1 ? DOMConsole.INFO : DOMConsole.ERR;
- // this.writeToConsole(channel, StringTypes.MESSAGE, "test_suite_grade", (grade * 100).toFixed(2));
- // return Promise.resolve(grade)
- // }).catch(err => {
- // this.domConsole.err("Erro inesperado durante o cálculo da nota.");// try and show error messages through domconsole
- // this.domConsole.err(err.message);
- // return Promise.resolve(0);
- // });
- } catch (error) {
- this.showErrorMessage(
- DOMConsole.ERR,
- StringTypes.MESSAGE,
- "unexpected_execution_error"
- );
- this.domConsole.err(error.message);
- return Promise.resolve(0);
- } finally {
- Config.setConfig(this.old_config);
- }
- }
- }
|