18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 08:17:09 +01:00
Files
maszyna/tests/unit/test_compartment_lights.cpp
T
Hirek 89258eb72c refactor(physics): the low voltage, the train heating and the electrodynamic brake as components
The rest of the electrics of physics::Vehicle beside the traction motors
becomes components, with English names:

  lowVoltage (LowVoltageSupply,   Battery batteryOn, BatteryVoltage,
  physics/components/lowvoltage.h) NominalBatteryVoltage, BatteryStart,
                                  Power110vIsAvailable / Power24vIsAvailable /
                                  Power24vVoltage power110vAvailable /
                                  power24vAvailable / power24vVoltage, the
                                  battery button of the cab: batteryButtonFired,
                                  batteryButtonImpulse, batteryButtonHeld,
                                  batteryButtonHoldTime
  trainHeating (TrainHeating)     Heating on, HeatingAllow allow,
                                  HeatingSwitchImpulse switchImpulse,
                                  HeatingPower power, EngineHeatingRPM engineRpm
  brakes.electrodynamic           the DynamicBrake* fields: type, ammeters,
  (ElectrodynamicBrake,           controllerPositions, controllerPosition,
  physics/components/braking.h)   resistance(1, 2), on, emuWorking;
                                  SplitEDPneumaticBrake splitFromPneumatic;
                                  the fans of the braking resistor (BRVentilators,
                                  BRVto, BRVtimer, Imaxrpc): resistorFansRunning,
                                  resistorFansSustain, resistorFansTimer,
                                  resistorPassiveMaxCurrent

The diesel-electric dynamic brake (DEDynamicBrake) and the currents of the
traction circuit (Im, Itot, EngineVoltage ...) stay for the traction stage.

No string literal changed (checked over all the changed files).

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
2026-11-29 03:15:56 +01:00

81 lines
2.9 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
using test::definition;
using test::vehicle;
// the compartment lights lamp of the cab (i-compartmentlights:) shows CompartmentLights.is_active of the cab's own
// vehicle, which LightsCheck() works out from the low voltage power and the compartment lights switch (eu07/maszyna#456)
// NOTE: the checks call LightsCheck() the way the vehicle update does, after setting the power by hand
namespace {
void lights_check(vehicle &Car) {
Car->LightsCheck(0.01);
}
} // namespace
TEST_CASE("compartment lights: the lights need low voltage power and the switch") {
vehicle car{definition::fiz("elf_v1/21we-a")};
REQUIRE(car->CompartmentLights.start_type == start_t::manual);
car->lowVoltage.power24vAvailable = false;
car->lowVoltage.power110vAvailable = false;
car->CompartmentLightsSwitch(true, range_t::local); // switch on, no power
lights_check(car);
CHECK_FALSE(car->CompartmentLights.is_active);
car->lowVoltage.power110vAvailable = true; // converter on
lights_check(car);
CHECK(car->CompartmentLights.is_active);
CHECK(car->CompartmentLights.intensity == doctest::Approx(1.0));
car->lowVoltage.power110vAvailable = false; // battery only: the lights stay on, dimmed
car->lowVoltage.power24vAvailable = true;
lights_check(car);
CHECK(car->CompartmentLights.is_active);
CHECK(car->CompartmentLights.intensity == doctest::Approx(0.5));
car->lowVoltage.power24vAvailable = false; // no power at all
lights_check(car);
CHECK_FALSE(car->CompartmentLights.is_active);
}
TEST_CASE("compartment lights: the off switch turns the lights off, the on switch back on") {
vehicle car{definition::fiz("elf_v1/21we-a")};
car->lowVoltage.power110vAvailable = true;
lights_check(car);
CHECK_FALSE(car->CompartmentLights.is_active); // manual start: off until switched on
// push buttons: the on button latches the lights, they stay on once it is released
car->CompartmentLightsSwitch(true, range_t::local);
lights_check(car);
car->CompartmentLightsSwitch(false, range_t::local);
lights_check(car);
CHECK(car->CompartmentLights.is_active);
car->CompartmentLightsSwitchOff(true, range_t::local);
lights_check(car);
CHECK_FALSE(car->CompartmentLights.is_active);
car->CompartmentLightsSwitchOff(false, range_t::local);
lights_check(car);
CHECK_FALSE(car->CompartmentLights.is_active); // still off once the off button is released
}
TEST_CASE("compartment lights: lights started automatically come on with the power alone") {
vehicle car{definition::fiz("elf_v1/21we-a").set("Cntrl", "CompartmentLightsStart", "Automatic")};
REQUIRE(car->CompartmentLights.start_type == start_t::automatic);
car->lowVoltage.power24vAvailable = false;
car->lowVoltage.power110vAvailable = false;
lights_check(car);
CHECK_FALSE(car->CompartmentLights.is_active);
car->lowVoltage.power110vAvailable = true;
lights_check(car);
CHECK(car->CompartmentLights.is_active);
}