18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 15:17:08 +01:00
Files
maszyna/tests/unit/test_line_contactors.cpp
T
Hirek bc2af26dd5 refactor(physics): the compressed air supply and the pipes keep their state to themselves
The compressor, the main reservoir and the pipes along the train
(physics/components/airsupply.h) become classes, as the parts of the main
circuit: the definition in `config`, the state behind queries and operations.

The step of the compressor (the programmer of a unit, its supply and its start
delay, the governor and its lock, the venting over the top pressure) moves into
AirCompressor::Update(), with what it needs from the vehicle as plain values
(CompressorInputs); the vehicle follows the step up as before (the switching
delay, the counter of the debug panel, the sound of the relay). The leaks and
the pressure of the main reservoir move into AirSupply, and the reservoir is
filled and drawn through it.

The fault of the compressor the scenery can set no longer adds 100000001 to its
pressures from TDynamicObject::Damage(): AirCompressor::SetFault() does the same
arithmetic, so a fault behaves exactly as it did.

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

131 lines
4.9 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
// the lamp of the open line contactors (eu07/maszyna#470): lit, it tells the start can be made, so it should go out
// where the start is cut off, by the pressure switch at 2 bar in the brake cylinders, not at 1 bar already
namespace {
test::vehicle locomotive(bool const Pressureswitch) {
test::vehicle vehicle{test::definition::load("wagon").set("Engine", "PressureSwitch", Pressureswitch)};
vehicle->lineContactors.Open(); // the line contactors open
vehicle->brakePipe.SetPressure(5.0);
return vehicle;
}
} // namespace
TEST_CASE("line contactors: with a pressure switch the lamp goes out with the start cut off") {
auto vehicle{locomotive(true)};
REQUIRE(vehicle->protection.config.hasPressureSwitch);
vehicle->brakes.cylinderPressure = 1.5; // braked, the start can still be made
vehicle->MotorConnectorsCheck(); // updates the pressure switch
REQUIRE_FALSE(vehicle->protection.PressureSwitchTripped());
CHECK(vehicle->LineContactorsLampLit());
vehicle->brakes.cylinderPressure = 2.5; // the pressure switch cuts the start off
vehicle->MotorConnectorsCheck();
REQUIRE(vehicle->protection.PressureSwitchTripped());
CHECK_FALSE(vehicle->LineContactorsLampLit());
}
TEST_CASE("line contactors: without a pressure switch the lamp goes out with the brakes applied, as before") {
auto vehicle{locomotive(false)};
vehicle->brakes.cylinderPressure = 0.5;
vehicle->MotorConnectorsCheck();
CHECK(vehicle->LineContactorsLampLit());
vehicle->brakes.cylinderPressure = 1.5;
vehicle->MotorConnectorsCheck();
CHECK_FALSE(vehicle->LineContactorsLampLit());
}
TEST_CASE("line contactors: closed contactors put the lamp out") {
auto vehicle{locomotive(true)};
vehicle->lineContactors.Close();
CHECK_FALSE(vehicle->LineContactorsLampLit());
}
TEST_CASE("line contactors: the ground relay and overload lamps follow the same rule") {
// all the lamps of the main circuit go out together, with the pressure switch where it's fitted
auto vehicle{locomotive(true)};
vehicle->brakes.cylinderPressure = 1.5;
vehicle->MotorConnectorsCheck();
CHECK(vehicle->MainCircuitLampsEnabled());
vehicle->brakes.cylinderPressure = 2.5;
vehicle->MotorConnectorsCheck();
CHECK_FALSE(vehicle->MainCircuitLampsEnabled());
}
// on the diesel-electric SU45 and SU46 (eu07/maszyna#263) the lamp tells just the line contactors are open: lit with the
// master controller at 0 and with the start cut off by too low a pressure in the main pipe, out on the power positions
namespace {
// the diesel-electric locomotive with its engine running and the brakes released, the master controller at 0
test::vehicle diesel_electric() {
test::vehicle vehicle{test::definition::load("diesel_electric")};
vehicle->CabOccupied = 1;
vehicle->CabActivisation();
vehicle->BatterySwitch(true);
vehicle->OilPumpSwitch(true);
vehicle->FuelPumpSwitch(true);
vehicle.run(20.0); // the oil pressure builds up
vehicle.hold_brake_pipe(5.0); // bar
vehicle->MainSwitch(true);
vehicle.run(30.0);
vehicle->DirectionForward();
vehicle.run(60.0); // the brakes release
return vehicle;
}
} // namespace
TEST_CASE("line contactors: on a diesel-electric the lamp is lit at 0 and goes out on a power position") {
auto vehicle{diesel_electric()};
REQUIRE(vehicle->EngineType == TEngineType::DieselElectric);
REQUIRE(vehicle->lineBreaker.IsClosed());
REQUIRE_FALSE(vehicle->protection.PressureSwitchTripped());
CHECK_FALSE(vehicle->lineContactors.IsClosed());
CHECK(vehicle->LineContactorsLampLit());
vehicle->IncMainCtrl(1);
vehicle.run(3.0);
CHECK(vehicle->lineContactors.IsClosed());
CHECK_FALSE(vehicle->LineContactorsLampLit());
vehicle->DecMainCtrl(1);
vehicle.run(3.0);
CHECK_FALSE(vehicle->lineContactors.IsClosed());
CHECK(vehicle->LineContactorsLampLit());
}
TEST_CASE("line contactors: on a diesel-electric the lamp lights with the contactors opened by too low a main pipe pressure") {
auto vehicle{diesel_electric()};
vehicle->IncMainCtrl(1);
vehicle.run(1.0);
vehicle->IncMainCtrl(1);
vehicle.run(2.0);
REQUIRE(vehicle->lineContactors.IsClosed());
vehicle.hold_brake_pipe(2.5); // bar, below the 3.6 bar of the pressure switch
vehicle.run(10.0);
REQUIRE(vehicle->protection.PressureSwitchTripped());
CHECK_FALSE(vehicle->lineContactors.IsClosed());
CHECK(vehicle->LineContactorsLampLit()); // it went out here
CHECK_FALSE(vehicle->MainCircuitLampsEnabled()); // the ground relay and overload lamps still go out with the start cut off
// the pressure back, the contactors stay open on the second position and the lamp stays lit, as it should;
// they close again only on the first one
vehicle.hold_brake_pipe(5.0);
vehicle.run(60.0);
REQUIRE_FALSE(vehicle->protection.PressureSwitchTripped());
CHECK_FALSE(vehicle->lineContactors.IsClosed());
CHECK(vehicle->LineContactorsLampLit());
vehicle->DecMainCtrl(1);
vehicle.run(3.0);
CHECK(vehicle->lineContactors.IsClosed());
CHECK_FALSE(vehicle->LineContactorsLampLit());
}