UNPKG

@syntest/core

Version:

The common core of the SynTest Framework

103 lines 3.15 kB
"use strict"; /* * Copyright 2020-2021 Delft University of Technology and SynTest contributors * * This file is part of SynTest Framework - SynTest Core. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.Encoding = void 0; const prng_1 = require("../util/prng"); const UserInterface_1 = require("../ui/UserInterface"); /** * Encoding of the search problem. * * @author Mitchell Olsthoorn */ class Encoding { /** * Constructor. */ constructor() { this._crowdingDistance = 0; this._rank = 0; this._id = prng_1.prng.uniqueId(20); this._objectives = new Map(); this._assertions = new Map(); (0, UserInterface_1.getUserInterface)().debug(`Created test case: ${this._id}`); } getCrowdingDistance() { return this._crowdingDistance; } setCrowdingDistance(value) { this._crowdingDistance = value; } getRank() { return this._rank; } setRank(value) { this._rank = value; } get id() { return this._id; } get assertions() { return this._assertions; } set assertions(value) { this._assertions = value; } /** * Return the execution result. */ getExecutionResult() { return this._executionResult; } /** * Store the execution result. * * @param executionResult The execution result to store */ setExecutionResult(executionResult) { this._executionResult = executionResult; } /** * Return the distance for the given objective. * * @param objectiveFunction The objective. */ getDistance(objectiveFunction) { if (this._objectives.has(objectiveFunction)) return this._objectives.get(objectiveFunction); else { // this part is needed for DynaMOSA // it may happen that the test was created when the objective in input was not part of the search yet // with this code, we keep the objective values up to date const distance = objectiveFunction.calculateDistance(this); this._objectives.set(objectiveFunction, distance); return distance; } } /** * Store the distance to an objective for this encoding. * * @param objectiveFunction The objective * @param distance The distance */ setDistance(objectiveFunction, distance) { this._objectives.set(objectiveFunction, distance); } } exports.Encoding = Encoding; //# sourceMappingURL=Encoding.js.map