Skip to content

Commit

Permalink
refactor: CarSimulatorEngine -> CarSimulator
Browse files Browse the repository at this point in the history
  • Loading branch information
EmileRolley committed Nov 21, 2024
1 parent b92f5e0 commit 73b646c
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 13 deletions.
4 changes: 2 additions & 2 deletions src/CarSimulatorEngine.ts → src/CarSimulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const ALTERNATIVES_RULES = RULE_NAMES.filter(
* can use {@link shallowCopy} to create a new instance with the same rules and
* inputs.
*/
export class CarSimulatorEngine {
export class CarSimulator {
private inputs: Questions = {}
private engine: Engine<RuleName>

Expand Down Expand Up @@ -271,7 +271,7 @@ export class CarSimulatorEngine {
* @returns A new instance of the engine with the same rules and inputs.
*/
public shallowCopy() {
const newEngine = new CarSimulatorEngine(true)
const newEngine = new CarSimulator(true)
newEngine.inputs = { ...this.inputs }
newEngine.engine = this.engine.shallowCopy()
return newEngine
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export type {
RuleValue,
} from "../publicodes-build"

export * from "./CarSimulatorEngine"
export * from "./CarSimulator"
18 changes: 8 additions & 10 deletions test/CarSimulatorEngine.test.ts → test/CarSimulator.test.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { describe, expect, test } from "vitest"
import { CarSimulatorEngine } from "../src/CarSimulatorEngine"
import { CarSimulator } from "../src/CarSimulator"

describe("CarSimulatorEngine", () => {
describe("new CarSimulatorEngine()", () => {
describe("CarSimulator", () => {
describe("new CarSimulator()", () => {
test("should return an instance of AidesVeloEngine with corrects rules parsed", () => {
const engine = new CarSimulatorEngine()
expect(engine).toBeInstanceOf(CarSimulatorEngine)
const engine = new CarSimulator()
expect(engine).toBeInstanceOf(CarSimulator)

const parsedRules = engine.getEngine().getParsedRules()
expect(parsedRules["coûts"]).toBeDefined()
expect(parsedRules["empreinte"]).toBeDefined()
})
})

const globalTestEngine = new CarSimulatorEngine()
const globalTestEngine = new CarSimulator()

describe("setInputs()", () => {
test("should correctly set the engine's situation", () => {
Expand Down Expand Up @@ -195,9 +195,7 @@ describe("CarSimulatorEngine", () => {
describe("evaluateAlternatives()", () => {
test("should return all possible alternatives with default values", () => {
const engine = globalTestEngine.shallowCopy()
console.time("evaluateAlternatives")
const alternatives = engine.evaluateAlternatives()
console.timeEnd("evaluateAlternatives")
// TODO: use engine.getOptions
const nbMotorisations = 3
const nbFuels = 4
Expand All @@ -218,8 +216,8 @@ describe("CarSimulatorEngine", () => {
expect(alternative.motorisation.value).toBeDefined()
expect(alternative.motorisation.isEnumValue).toBeTruthy()
if (alternative.motorisation.value !== "électrique") {
expect(alternative.fuel.value).toBeDefined()
expect(alternative.fuel.isEnumValue).toBeTruthy()
expect(alternative.fuel?.value).toBeDefined()
expect(alternative.fuel?.isEnumValue).toBeTruthy()
} else {
expect(alternative.fuel).toBeUndefined()
}
Expand Down

0 comments on commit 73b646c

Please sign in to comment.