|
@@ -1,16 +1,11 @@
|
|
-import { Decimal } from 'decimal.js';
|
|
|
|
import line_i18n from 'line-i18n'
|
|
import line_i18n from 'line-i18n'
|
|
import { IVProgProcessor } from "./../processor/ivprogProcessor";
|
|
import { IVProgProcessor } from "./../processor/ivprogProcessor";
|
|
-import { InputTest } from "./../util/inputTest";
|
|
|
|
-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 { OutputMatching } from './output_matching/output_matching';
|
|
import { OutputMatching } from './output_matching/output_matching';
|
|
|
|
|
|
|
|
|
|
const LocalizedStrings = LocalizedStringsService.getInstance();
|
|
const LocalizedStrings = LocalizedStringsService.getInstance();
|
|
-const list_joiner = LocalizedStrings.getUI("text_join_assessment_outputs");
|
|
|
|
|
|
|
|
const StringTypes = line_i18n.StringTypes;
|
|
const StringTypes = line_i18n.StringTypes;
|
|
|
|
|
|
@@ -77,89 +72,6 @@ export class IVProgAssessment {
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- evaluateTestCase (prog, inputList, expectedOutputs, name, accumulator) {
|
|
|
|
- const outerThis = this;
|
|
|
|
- const input = new InputTest(inputList);
|
|
|
|
- const output = new OutputTest();
|
|
|
|
- prog.registerInput(input);
|
|
|
|
- prog.registerOutput(output);
|
|
|
|
- const startTime = Date.now()
|
|
|
|
- return prog.interpretAST().then( () => {
|
|
|
|
- const millis = Date.now() - startTime;
|
|
|
|
- if (input.inputList.length !== input.index) {
|
|
|
|
- outerThis.showErrorMessage('test_case_few_reads', name+1);
|
|
|
|
- outerThis.showInfoMessage('test_case_duration', millis);
|
|
|
|
- return Promise.resolve(accumulator);
|
|
|
|
- } else if (output.list.length != expectedOutputs.length) {
|
|
|
|
- outerThis.showErrorMessage('test_case_failed', name + 1, inputList.join(list_joiner),
|
|
|
|
- expectedOutputs.join(list_joiner), output.list.join(list_joiner));
|
|
|
|
- outerThis.showInfoMessage('test_case_duration', millis);
|
|
|
|
- // must check for a partial match of the generated output
|
|
|
|
- const numMatchedOutputs = output.list.reduce((acc, actualOutput, index) => {
|
|
|
|
- if(outerThis.checkOutputValues(actualOutput, expectedOutputs[index])) {
|
|
|
|
- return acc + 1;
|
|
|
|
- } else {
|
|
|
|
- return acc;
|
|
|
|
- }
|
|
|
|
- }, 0);
|
|
|
|
- const maxLength = Math.max(expectedOutputs.length, output.list.length);
|
|
|
|
- return Promise.resolve(accumulator + (numMatchedOutputs/maxLength));
|
|
|
|
- } else {
|
|
|
|
- const isOk = outerThis.checkOutputLists(output.list, expectedOutputs);
|
|
|
|
- if(!isOk) {
|
|
|
|
- outerThis.showErrorMessage('test_case_failed', name + 1, inputList.join(list_joiner),
|
|
|
|
- expectedOutputs.join(list_joiner), output.list.join(list_joiner));
|
|
|
|
- outerThis.showInfoMessage('test_case_duration', millis);
|
|
|
|
- return Promise.resolve(accumulator);
|
|
|
|
- } else {
|
|
|
|
- outerThis.showInfoMessage('test_case_success', name + 1);
|
|
|
|
- outerThis.showInfoMessage('test_case_duration', millis);
|
|
|
|
- return Promise.resolve(accumulator + 1);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }).catch( error => {
|
|
|
|
- outerThis.showErrorMessage('test_case_failed_exception', name + 1, error.message);
|
|
|
|
- return Promise.resolve(accumulator);
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- partialEvaluateTestCase (prog, inputList, expectedOutputs, name) {
|
|
|
|
- return this.evaluateTestCase.bind(this, prog, inputList, expectedOutputs, name);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- checkOutputLists (actualOutputs, expectedOutputs) {
|
|
|
|
- for (let i = 0; i < actualOutputs.length; i++) {
|
|
|
|
- const outValue = actualOutputs[i];
|
|
|
|
- const expectedValue = expectedOutputs[i];
|
|
|
|
- if(!this.checkOutputValues(outValue, expectedValue)) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- checkOutputValues (actualValue, expectedValue) {
|
|
|
|
- let castNumberA = parseFloat(actualValue);
|
|
|
|
- if(!Number.isNaN(castNumberA)) {
|
|
|
|
- let castNumberB = parseFloat(expectedValue);
|
|
|
|
- if(Number.isNaN(castNumberB)) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- castNumberA = new Decimal(castNumberA);
|
|
|
|
- castNumberB = new Decimal(castNumberB);
|
|
|
|
- const decimalPlaces = Math.min(castNumberB.dp(), Config.decimalPlaces);
|
|
|
|
- castNumberA = new Decimal(castNumberA.toFixed(decimalPlaces, Decimal.ROUND_FLOOR));
|
|
|
|
- castNumberB = new Decimal(castNumberB.toFixed(decimalPlaces, Decimal.ROUND_FLOOR));
|
|
|
|
- const aEqualsB = castNumberA.eq(castNumberB);
|
|
|
|
- if (!aEqualsB) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- } else if(actualValue != expectedValue) {
|
|
|
|
- return false;
|
|
|
|
- }
|
|
|
|
- return true;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
showErrorMessage (errorID, ...args) {
|
|
showErrorMessage (errorID, ...args) {
|
|
this.domConsole.err(LocalizedStrings.getError(errorID, args));
|
|
this.domConsole.err(LocalizedStrings.getError(errorID, args));
|
|
}
|
|
}
|