18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 11:47:06 +01:00
Files
maszyna/tests/unit/test_compartment_lights.cpp
Hirek 160ffe2147 refactor(physics): the low voltage, the train heating and the pantographs keep their state to themselves
As the parts of the main circuit: the battery and the low voltage circuits,
the train heating, the circuit of the pantographs and their air become classes
with the definition in `config` and the state behind queries and operations.

The step of the air of the pantographs (the small compressor, the three-way
cock, the leaks, the pressure switch) moves into PantographAir::Update(), which
gets what it needs as plain values (PantographAirSupply) and reports a trip of
the pressure switch, so the vehicle opens its line breaker or switches the
converter of a unit off as before. The drain of the battery and its limits move
into LowVoltageSupply. The latch of the held battery button of the cab moves
from the physics to TTrain, where the button is.

The gauges of the cab bind to the values they show through const pointers
(TGauge::Assign*() take them), so the queries they bind to return const
references and the cab reads the state live without being able to change it.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
2026-11-29 10:08:54 +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.Set24vAvailableForTest(false);
car->lowVoltage.Set110vAvailableForTest(false);
car->CompartmentLightsSwitch(true, range_t::local); // switch on, no power
lights_check(car);
CHECK_FALSE(car->CompartmentLights.is_active);
car->lowVoltage.Set110vAvailableForTest(true); // converter on
lights_check(car);
CHECK(car->CompartmentLights.is_active);
CHECK(car->CompartmentLights.intensity == doctest::Approx(1.0));
car->lowVoltage.Set110vAvailableForTest(false); // battery only: the lights stay on, dimmed
car->lowVoltage.Set24vAvailableForTest(true);
lights_check(car);
CHECK(car->CompartmentLights.is_active);
CHECK(car->CompartmentLights.intensity == doctest::Approx(0.5));
car->lowVoltage.Set24vAvailableForTest(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.Set110vAvailableForTest(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.Set24vAvailableForTest(false);
car->lowVoltage.Set110vAvailableForTest(false);
lights_check(car);
CHECK_FALSE(car->CompartmentLights.is_active);
car->lowVoltage.Set110vAvailableForTest(true);
lights_check(car);
CHECK(car->CompartmentLights.is_active);
}