18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 17:37:09 +01:00
Files
maszyna/tests/unit/test_engine_shutdown.cpp
T
Hirek 84f1aa2515 refactor(physics): the controllers and the switches of the cab are private to the vehicle
The positions of the master and the secondary controller, of the analog
controller and of the lights selector, the occupied cab, the horns, the radio
and its fuse, the radio-stop, the wipers' switch, the dimmer, the mirrors'
button, the end-of-train signalling and the forced resistor fans: fourteen
fields the cab, the AI, the scenery and the tests wrote straight into
physics::Vehicle are private now. The rest of the simulator reads them through
queries named as the fields were (MainCtrlPos(), Radio(), ...) and changes them
through operations (SetMainCtrlPos(), SetRadio(), ...), so every place that
moves a controller past its own stepping (IncMainCtrl()) is named and can be
found; the compiler keeps anything else out. Inside the vehicle they keep
their meaning under camelCase names. The queries return const references, as
the gauges of the cab bind to them.

The .fiz keys are untouched.

No change in behaviour: the golden traces recorded on dfb43c4f match bit for bit.
2026-11-29 12:26:21 +01:00

75 lines
3.0 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
// stopping the engine of a diesel shunter like the SM03 (eu07/maszyna#427): its fuel pump starts on its own with the
// engine and the engine runs the converter which feeds the low voltage circuit, so neither the fuel pump switch nor the
// battery switch stop it. the cab has only the starter button, and the command opening the main circuit has to stop it
namespace {
// the shunter with its engine started from the cab and idling
test::vehicle running_shunter() {
test::vehicle shunter{test::definition::load("diesel_shunter")};
shunter->SetCabOccupied(1);
shunter->CabActivisation();
shunter->BatterySwitch(true);
shunter->OilPumpSwitch(true);
shunter.run(20.0); // the oil pressure builds up
shunter->MainSwitch(true);
shunter.run(15.0);
return shunter;
}
} // namespace
TEST_CASE("engine shutdown: the shunter starts with the starter button") {
auto shunter{running_shunter()};
REQUIRE(shunter->EngineType == TEngineType::DieselEngine);
REQUIRE(shunter->FuelPump.start_type == start_t::automatic);
CHECK(shunter->lineBreaker.IsClosed());
CHECK(shunter->FuelPump.is_active);
CHECK(shunter->enrot > 0.9 * shunter->diesel.minRevolutions);
}
TEST_CASE("engine shutdown: neither the fuel pump switch nor the battery switch stop the engine") {
auto shunter{running_shunter()};
shunter->FuelPumpSwitchOff(true, range_t::local); // the pump started automatically ignores its switch
shunter.run(10.0);
CHECK(shunter->lineBreaker.IsClosed());
shunter->BatterySwitch(false);
shunter.run(10.0);
CHECK(shunter->lowVoltage.Is110vAvailable()); // the converter run by the engine keeps feeding the fuel pump
CHECK(shunter->lineBreaker.IsClosed());
CHECK(shunter->enrot > 0.9 * shunter->diesel.minRevolutions);
}
TEST_CASE("engine shutdown: the command opening the main circuit stops the engine and it stays stopped") {
auto shunter{running_shunter()};
REQUIRE(shunter->MainCircuitOpensWithStarterOnly()); // the cab passes the command on with only the starter button
CHECK(shunter->MainSwitch(false));
shunter.run(20.0);
CHECK_FALSE(shunter->lineBreaker.IsClosed());
CHECK_FALSE(shunter->FuelPump.is_active);
CHECK(shunter->enrot == 0.0);
}
TEST_CASE("engine shutdown: the engine starts again after it was stopped") {
auto shunter{running_shunter()};
shunter->MainSwitch(false);
shunter.run(20.0);
REQUIRE(shunter->enrot == 0.0);
shunter->MainSwitch(true);
shunter.run(15.0);
CHECK(shunter->lineBreaker.IsClosed());
CHECK(shunter->enrot > 0.9 * shunter->diesel.minRevolutions);
}
TEST_CASE("engine shutdown: vehicles without a diesel keep ignoring the command with only the button closing the circuit") {
test::vehicle wagon{test::definition::load("wagon")};
CHECK_FALSE(wagon->MainCircuitOpensWithStarterOnly());
test::vehicle electric{test::definition::load("wagon").set("Engine", "EngineType", "ElectricSeriesMotor")};
REQUIRE(electric->EngineType == TEngineType::ElectricSeriesMotor);
CHECK_FALSE(electric->MainCircuitOpensWithStarterOnly());
}