mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-12-01 19:57:06 +01:00
5879c228dc
53 fields of physics::Vehicle that only the vehicle itself writes, and the rest
of the simulator reads, are private, with a query each, named as the field was
(Vmax(), TotalMass(), Ft(), nrot(), NAxles(), PhysicActivation(), ...): the
compiler now keeps the cab, the AI, the scenery, the renderer and the tests from
changing what the definition gives or the physics works out. The fields were
picked by what is never written outside the class, of plain types, with no
other member of the same name to confuse; inside the class they keep their
meaning under camelCase names. The one place outside that cleared a flag of
the AI through a reference does it through ClearAIFlag().
No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
57 lines
2.6 KiB
C++
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));
|
|
}
|