123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103 |
- 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";
- import { Assistant } from "../assistant/assistant";
- const StringTypes = line_i18n.StringTypes;
- export class IVProgAssessment extends Assessment {
- constructor (ast_code, exerciseType, testCases, domConsole) {
- super(ast_code, exerciseType, 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)
- );
- const ivprog_assistant = new Assistant();
- let textArray = ivprog_assistant.analise("http://127.0.0.1:81/moodle/mod/iassign/endpoint.php",this.exerciseType,results);
- Promise.resolve(textArray).then((Text) => {
- this.writeToConsole(
- DOMConsole.INFO,
- StringTypes.MESSAGE,
- "assistant_content",
- results[0].generateAssistantOutput(Text[0],Text[1])
- );
- });
- 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);
- }
- }
- }
|