Skip to content

Commit 73b646c

Browse files
committed
refactor: CarSimulatorEngine -> CarSimulator
1 parent b92f5e0 commit 73b646c

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

src/CarSimulatorEngine.ts renamed to src/CarSimulator.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ export const ALTERNATIVES_RULES = RULE_NAMES.filter(
9494
* can use {@link shallowCopy} to create a new instance with the same rules and
9595
* inputs.
9696
*/
97-
export class CarSimulatorEngine {
97+
export class CarSimulator {
9898
private inputs: Questions = {}
9999
private engine: Engine<RuleName>
100100

@@ -271,7 +271,7 @@ export class CarSimulatorEngine {
271271
* @returns A new instance of the engine with the same rules and inputs.
272272
*/
273273
public shallowCopy() {
274-
const newEngine = new CarSimulatorEngine(true)
274+
const newEngine = new CarSimulator(true)
275275
newEngine.inputs = { ...this.inputs }
276276
newEngine.engine = this.engine.shallowCopy()
277277
return newEngine

src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,4 @@ export type {
99
RuleValue,
1010
} from "../publicodes-build"
1111

12-
export * from "./CarSimulatorEngine"
12+
export * from "./CarSimulator"

test/CarSimulatorEngine.test.ts renamed to test/CarSimulator.test.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
import { describe, expect, test } from "vitest"
2-
import { CarSimulatorEngine } from "../src/CarSimulatorEngine"
2+
import { CarSimulator } from "../src/CarSimulator"
33

4-
describe("CarSimulatorEngine", () => {
5-
describe("new CarSimulatorEngine()", () => {
4+
describe("CarSimulator", () => {
5+
describe("new CarSimulator()", () => {
66
test("should return an instance of AidesVeloEngine with corrects rules parsed", () => {
7-
const engine = new CarSimulatorEngine()
8-
expect(engine).toBeInstanceOf(CarSimulatorEngine)
7+
const engine = new CarSimulator()
8+
expect(engine).toBeInstanceOf(CarSimulator)
99

1010
const parsedRules = engine.getEngine().getParsedRules()
1111
expect(parsedRules["coûts"]).toBeDefined()
1212
expect(parsedRules["empreinte"]).toBeDefined()
1313
})
1414
})
1515

16-
const globalTestEngine = new CarSimulatorEngine()
16+
const globalTestEngine = new CarSimulator()
1717

1818
describe("setInputs()", () => {
1919
test("should correctly set the engine's situation", () => {
@@ -195,9 +195,7 @@ describe("CarSimulatorEngine", () => {
195195
describe("evaluateAlternatives()", () => {
196196
test("should return all possible alternatives with default values", () => {
197197
const engine = globalTestEngine.shallowCopy()
198-
console.time("evaluateAlternatives")
199198
const alternatives = engine.evaluateAlternatives()
200-
console.timeEnd("evaluateAlternatives")
201199
// TODO: use engine.getOptions
202200
const nbMotorisations = 3
203201
const nbFuels = 4
@@ -218,8 +216,8 @@ describe("CarSimulatorEngine", () => {
218216
expect(alternative.motorisation.value).toBeDefined()
219217
expect(alternative.motorisation.isEnumValue).toBeTruthy()
220218
if (alternative.motorisation.value !== "électrique") {
221-
expect(alternative.fuel.value).toBeDefined()
222-
expect(alternative.fuel.isEnumValue).toBeTruthy()
219+
expect(alternative.fuel?.value).toBeDefined()
220+
expect(alternative.fuel?.isEnumValue).toBeTruthy()
223221
} else {
224222
expect(alternative.fuel).toBeUndefined()
225223
}

0 commit comments

Comments
 (0)