18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 19:57:06 +01:00
Files
maszyna/tests/unit/test_equipment_faults.cpp
T
Hirek 6b9558f588 refactor(physics): the faults of the equipment are a named set the physics sets
The faults the scenery or the network sets on a vehicle (TDynamicObject::
Damage() with the number of a message, held as EngDmgFlag and tested as its
bits 1, 4) are EquipmentFault and EquipmentFaultSet, and what each does moves
out of TDynamicObject into physics::Vehicle::SetEquipmentFaults(). The number of
a message comes in through FromBits() and goes back out through Bits(), as it
was.

The faults of the control and of the camshaft still hold the start and the
steps of the controller by delays moved out of reach by 100000001 and back,
the very same arithmetic, now named and in one place. Tests of it are added
(test_equipment_faults.cpp), as nothing reached it before.

The setters of the parts that took a parameter named as one of their queries
(Pressure, Voltage) take Value instead.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
2026-11-29 10:56:17 +01:00

57 lines
2.6 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
// the faults of the equipment the scenery or the network sets on a vehicle (physics::Vehicle::SetEquipmentFaults(),
// TDynamicObject::Damage() with the number of a message)
TEST_CASE("equipment faults: the number of a message comes back as it went in") {
auto const faults{EquipmentFaultSet::FromBits(0x2A)};
CHECK(faults.HasAll(EquipmentFault::control));
CHECK(faults.HasAll(EquipmentFault::compressor));
CHECK(faults.HasAll(EquipmentFault::emergencyBrake));
CHECK_FALSE(faults.HasAny(EquipmentFault::differentialRelay | EquipmentFault::converter | EquipmentFault::camshaft));
CHECK(faults.Bits() == 0x2A);
}
TEST_CASE("equipment faults: the fault of the control opens the line contactors and holds the start until it clears") {
test::vehicle loco{test::definition::fiz("4e_v1/4e")};
auto const delay{loco->InitialCtrlDelay};
loco->lineContactors.Close();
loco->SetEquipmentFaults(EquipmentFault::control);
CHECK(loco->equipmentFaults.HasAll(EquipmentFault::control));
CHECK_FALSE(loco->lineContactors.IsClosed());
CHECK(loco->InitialCtrlDelay > 100000000.0);
// set again, it doesn't move the delay further
loco->SetEquipmentFaults(EquipmentFault::control);
CHECK(loco->InitialCtrlDelay < 200000000.0);
loco->SetEquipmentFaults({});
CHECK(loco->equipmentFaults.Empty());
CHECK(loco->InitialCtrlDelay == doctest::Approx(delay));
}
TEST_CASE("equipment faults: the fault of the compressor moves its pressures out of reach, and back") {
test::vehicle loco{test::definition::fiz("4e_v1/4e")};
auto const minpressure{loco->air.compressor.config.minPressure};
auto const maxpressure{loco->air.compressor.config.maxPressure};
REQUIRE(minpressure > 0.0);
loco->SetEquipmentFaults(EquipmentFault::compressor);
CHECK(loco->air.compressor.config.minPressure < 0.0);
CHECK(loco->air.compressor.config.maxPressure < 0.0);
loco->SetEquipmentFaults({});
CHECK(loco->air.compressor.config.minPressure == doctest::Approx(minpressure));
CHECK(loco->air.compressor.config.maxPressure == doctest::Approx(maxpressure));
}
TEST_CASE("equipment faults: the fault of the camshaft holds the steps of the controller until it clears") {
test::vehicle loco{test::definition::fiz("4e_v1/4e")};
auto const delay{loco->CtrlDelay};
auto const downdelay{loco->CtrlDownDelay};
loco->SetEquipmentFaults(EquipmentFault::camshaft);
CHECK(loco->CtrlDelay > 100000000.0);
CHECK(loco->CtrlDownDelay > 100000000.0);
loco->SetEquipmentFaults({});
CHECK(loco->CtrlDelay == doctest::Approx(delay));
CHECK(loco->CtrlDownDelay == doctest::Approx(downdelay));
}