18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 23:17:56 +01:00
Files
maszyna/tests/unit/test_line_contactors.cpp
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

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->SetCabOccupied(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());
}