mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 06:26:01 +01:00
Merge remote-tracking branch 'origin/master' into fix/ws-hold-coil-lever-bistable
# Conflicts: # vehicle/Train.cpp
This commit is contained in:
46
tests/unit/data/diesel_electric.json
Normal file
46
tests/unit/data/diesel_electric.json
Normal file
@@ -0,0 +1,46 @@
|
||||
{
|
||||
"_comment": "Diesel-electric locomotive made after the SU46 (303D): the line contactors close on the first power position of the master controller, the pressure switch (on by default) opens them with too low a pressure in the main pipe or the brakes applied.",
|
||||
"Param": { "Category": "train", "M": 105000, "Mred": 15000, "Vmax": 120, "PWR": 1400, "SandCap": 400 },
|
||||
"Dimensions": { "L": 18.99, "H": 4.292, "W": 2.904, "Cx": 0.3 },
|
||||
"Wheels": { "D": 1.1, "AIM": 4000, "Tw": 1.435, "Axle": "Co'Co'", "Ad": 1.75, "Bd": 10.3, "Rmin": 100 },
|
||||
"Brake": {
|
||||
"BrakeValve": "LSt", "NBpA": 4, "MBF": 85.0, "MaxBP": 4.4, "LocMaxBP": 4.4, "MaxASBP": 1.3, "RM": 0.71, "BCN": 12, "BCR": 0.114,
|
||||
"BCD": 0.06, "BCM": 5.84, "HiPP": 5, "LoPP": 3.5, "Vv": 0.9, "MinCP": 7, "MaxCP": 8.5, "CompressorSpeed": 0.05, "BCS": 1, "BSA": 2,
|
||||
"BM": "P10-Bgu", "CompressorPower": "Converter", "BVV": 200, "BRE": 0.8
|
||||
},
|
||||
"BuffCoupl": { "CType": "Screw", "kB": 9200, "DmaxB": 0.15, "FmaxB": 740, "kC": 4800, "DmaxC": 0.15, "FmaxC": 780, "beta": 0.58, "AllowedFlag": 103 },
|
||||
"Cntrl": {
|
||||
"BrakeHandle": "FV4a", "LocBrakeHandle": "FD1", "BrakeSystem": "Pneumatic", "BDelay1": 15, "BDelay2": 6, "BDelay3": 36, "BDelay4": 32,
|
||||
"ASB": "Manual", "LocalBrake": "PneumaticBrake", "MCPN": 15, "SCPN": 4, "AutoRelay": "Yes", "IniCDelay": 0.5, "SCDelay": 0.1,
|
||||
"BrakeDelays": "GPR", "ConverterStart": "Automatic", "ConverterStartDelay": 10
|
||||
},
|
||||
"Light": { "Light": "Generator", "LGeneratorEngine": "ElectricSeriesMotor", "LMaxVoltage": 110, "LMaxCurrent": 100 },
|
||||
"Engine": {
|
||||
"AIM": 1.6, "EngineType": "DumbDE", "Trans": "18:62", "Ftmax": 317000, "Flat": 0, "Vhyp": 15.0, "Vadd": 3.8, "Cr": 1.0, "RelayType": 46,
|
||||
"OilMinPressure": 0.055, "OilMaxPressure": 0.6, "WaterMinTemperature": 40, "WaterMaxTemperature": 92, "WaterCoolingTemperature": 76,
|
||||
"HeatKW": 0.068599, "HeatKV": 0.3, "HeatKFE": 1, "HeatKFS": 87.76269, "HeatKFO": 26.72716, "HeatKFO2": 57.72
|
||||
},
|
||||
"Circuit": { "CircuitRes": 0.01, "ImaxLo": 3300, "IminLo": 2500 },
|
||||
"_power": "rows: engine speed [rpm], power [kW], generator voltage limit, current limit, one per master controller position",
|
||||
"WWList": {
|
||||
"Size": 15,
|
||||
"rows": [
|
||||
[696, 0, 0, 0],
|
||||
[696, 0, 0, 0],
|
||||
[696, 80, 350, 1000],
|
||||
[696, 80, 350, 1000],
|
||||
[763, 214, 455, 1400],
|
||||
[830, 321, 500, 1600],
|
||||
[897, 428, 545, 1800],
|
||||
[964, 535, 590, 2000],
|
||||
[1031, 642, 635, 2200],
|
||||
[1098, 748, 680, 2400],
|
||||
[1165, 855, 725, 2600],
|
||||
[1232, 962, 770, 2800],
|
||||
[1299, 1069, 815, 3000],
|
||||
[1366, 1176, 865, 3200],
|
||||
[1433, 1283, 910, 3400],
|
||||
[1500, 1390, 960, 3600]
|
||||
]
|
||||
}
|
||||
}
|
||||
53
tests/unit/data/diesel_shunter.json
Normal file
53
tests/unit/data/diesel_shunter.json
Normal file
@@ -0,0 +1,53 @@
|
||||
{
|
||||
"_comment": "Diesel shunter with a mechanical gearbox, made after the SM03 (Ls150): the fuel pump starts on its own with the engine, a converter run by the engine feeds the low voltage circuit, the only cab control of the engine is the starter button.",
|
||||
"Param": { "Category": "train", "M": 23200, "Vmax": 25.68, "PWR": 111.855, "SandCap": 200 },
|
||||
"Dimensions": { "L": 6.94, "H": 3.21, "W": 2.97, "Cx": 0.3 },
|
||||
"Wheels": { "D": 0.94, "Tw": 1.435, "AIM": 250, "Axle": "B", "Ad": 2.5, "Bd": 2.5, "Rmin": 50, "BearingType": "Roll" },
|
||||
"Brake": {
|
||||
"BrakeValve": "K", "NBpA": 2, "MBF": 85.0, "MaxBP": 3.5, "LocMaxBP": 5.0, "BCN": 1, "BCR": 0.114, "BCD": 0.12, "BCM": 10.0,
|
||||
"HiPP": 5, "LoPP": 3.5, "Vv": 0.3, "MinCP": 7.0, "MaxCP": 8.0, "CompressorSpeed": 0.0125, "CompressorPower": "Main",
|
||||
"BCS": 0.8, "BSA": 0, "BM": "P10-Bg", "BVV": 40, "BRE": 0.9
|
||||
},
|
||||
"BuffCoupl": { "CType": "Screw", "kB": 9200, "DmaxB": 0.15, "FmaxB": 740, "kC": 4800, "DmaxC": 0.15, "FmaxC": 780, "beta": 0.58, "AllowedFlag": 3 },
|
||||
"Cntrl": {
|
||||
"BrakeSystem": "Pneumatic", "BDelay1": 15, "BDelay2": 4, "ASB": "Manual", "LocalBrake": "PneumaticBrake", "ManualBrake": "Yes",
|
||||
"DynamicBrake": "Passive", "MCPN": 9, "SCPN": 7, "AutoRelay": "No", "IniCDelay": 0.5, "SCDelay": 0.1, "BrakeDelays": "P",
|
||||
"BrakeHandle": "Knorr", "LocBrakeHandle": "Knorr", "FuelStart": "Automatic", "ConverterStart": "Automatic"
|
||||
},
|
||||
"Light": { "Light": "Generator", "LGeneratorEngine": "ElectricSeriesMotor", "LMaxVoltage": 24, "LMaxCurrent": 100 },
|
||||
"Engine": {
|
||||
"EngineType": "DieselEngine", "Trans": "1:1", "nmin": 900, "nmax": 1500, "nmax_cutoff": 1550, "AIM": 100,
|
||||
"OilMinPressure": 0.343, "OilMaxPressure": 0.686, "WaterCoolingTemperature": 80, "WaterShutters": "yes", "WaterAuxCircuit": "no",
|
||||
"HeatKFO": 160, "HeatKFO2": 180, "HeatKFS": 160, "HeatKFE": 7, "HeatKW": 2, "HeatKV": 0.3, "IsTC": "No", "EUS": 0.35, "EDS": 1.0
|
||||
},
|
||||
"_gears": "rows: gear, ratio, engagement speed, top speed; the even ones neutral",
|
||||
"MotorParamTable": {
|
||||
"minVelfullengage": 3.8, "engageDia": 1, "engageMaxForce": 800, "engagefriction": 1,
|
||||
"rows": [
|
||||
[0, 0, 0, -1],
|
||||
[1, 46.88, -1, 5.73],
|
||||
[2, 0, 0, -1],
|
||||
[3, 28.65, 2.9, 9.42],
|
||||
[4, 0, 0, -1],
|
||||
[5, 17.12, 4.7, 15.69],
|
||||
[6, 0, 0, -1],
|
||||
[7, 10.46, 10.6, 100]
|
||||
]
|
||||
},
|
||||
"_throttle": "rows: position, fill, speed governor mode; position 0 idles",
|
||||
"DList": {
|
||||
"Size": 9, "Mmax": 784.5, "nMmax": 15, "Mnmax": 686.4, "nmax": 25, "nominalfill": 1, "Mstand": 200.0,
|
||||
"rows": [
|
||||
[0, 0.1, 0],
|
||||
[1, 0.2, 2],
|
||||
[2, 0.3, 2],
|
||||
[3, 0.4, 2],
|
||||
[4, 0.5, 2],
|
||||
[5, 0.6, 2],
|
||||
[6, 0.7, 2],
|
||||
[7, 0.8, 2],
|
||||
[8, 0.9, 2],
|
||||
[9, 1.0, 2]
|
||||
]
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,21 @@
|
||||
|
||||
namespace test {
|
||||
|
||||
namespace {
|
||||
|
||||
// whether the pressure switch of a vehicle in the train still cuts the start off: a half of a locomotive whose
|
||||
// switch is on when the controller leaves zero doesn't close its line contactors until the controller is back at zero
|
||||
bool start_cut_off(consist &Train) {
|
||||
for (std::size_t i = 0; i < Train.size(); ++i) {
|
||||
if (Train[i].mover().ControlPressureSwitch) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
scenario::scenario(std::string Name, std::vector<channel> Channels, track const &Track) : m_name(std::move(Name)), m_channels(std::move(Channels)), m_track(Track) {
|
||||
reseed_random();
|
||||
}
|
||||
@@ -53,6 +68,11 @@ void scenario::get_going() {
|
||||
|
||||
void scenario::full_power(double Seconds) {
|
||||
auto &controlling{driver().controlling};
|
||||
// as a driver does, wait for the brakes to let go far enough for every pressure switch of the train to allow the
|
||||
// start; otherwise whether all the halves of a locomotive start hangs on thousandths of a bar of their cylinders
|
||||
for (int i = 0; i < 120 && start_cut_off(m_train); ++i) {
|
||||
wait(1.0);
|
||||
}
|
||||
controlling.IncMainCtrl(1);
|
||||
for (int i = 0; i < 90 && false == controlling.StLinFlag; ++i) {
|
||||
wait(1.0);
|
||||
|
||||
@@ -113,3 +113,93 @@ TEST_CASE("compressor: without a pressure switch the air over the cut-out pressu
|
||||
REQUIRE(vehicle->CompressorFlag); // nothing stops it
|
||||
CHECK(vehicle->CompressedVolume < 8.5 * 0.81); // a fifth of the air let out
|
||||
}
|
||||
|
||||
TEST_CASE("compressor: an engine stopped before the delay passed counts the whole delay again") {
|
||||
auto vehicle{compressor_vehicle(30.0)};
|
||||
vehicle->Mains = true; // engine started
|
||||
run_compressor(vehicle, 20.0);
|
||||
REQUIRE_FALSE(vehicle->CompressorFlag);
|
||||
|
||||
vehicle->Mains = false; // engine stopped, 10 s short of the delay
|
||||
run_compressor(vehicle, 1.0);
|
||||
vehicle->Mains = true;
|
||||
run_compressor(vehicle, 15.0); // 36 s since the first start, but only 15 s since this one
|
||||
CHECK_FALSE(vehicle->CompressorFlag);
|
||||
|
||||
run_compressor(vehicle, 15.1);
|
||||
CHECK(vehicle->CompressorFlag);
|
||||
}
|
||||
|
||||
TEST_CASE("compressor: the start delay holds back a compressor switched on by hand too") {
|
||||
auto vehicle{compressor_vehicle(30.0)};
|
||||
vehicle->CompressorStart = start_t::manual;
|
||||
vehicle->CompressorAllow = true; // switch in the cabinet on before the engine start
|
||||
vehicle->Mains = true;
|
||||
|
||||
run_compressor(vehicle, 29.9);
|
||||
CHECK_FALSE(vehicle->CompressorFlag);
|
||||
run_compressor(vehicle, 0.2);
|
||||
CHECK(vehicle->CompressorFlag);
|
||||
}
|
||||
|
||||
TEST_CASE("compressor: the start delay is read from the brake section") {
|
||||
auto const delay{[](std::string const &Section) {
|
||||
return vehicle{definition::load("wagon").set(Section, "CompressorStartDelay", 30)}->CompressorStartDelay;
|
||||
}};
|
||||
CHECK(delay("Brake") == doctest::Approx(30.0));
|
||||
CHECK(delay("Cntrl") == doctest::Approx(0.0)); // the key isn't taken from the control section
|
||||
}
|
||||
|
||||
namespace {
|
||||
|
||||
// 401Da: the compressor runs from the 110 V of the auxiliary generator driven by the engine, here the converter
|
||||
// started with the main circuit, which gets up to voltage the converter start delay after the engine start
|
||||
definition generator_vehicle(double const ConverterDelay, double const CompressorDelay) {
|
||||
return definition::load("cab_vehicle")
|
||||
.set("Param", "PWR", 370)
|
||||
.set("Light", "Light", "Generator")
|
||||
.set("Light", "LMaxVoltage", 110)
|
||||
.set("Brake", "Vv", 0.6)
|
||||
.set("Brake", "MinCP", 6.5)
|
||||
.set("Brake", "MaxCP", 8.0)
|
||||
.set("Brake", "CompressorSpeed", 0.003)
|
||||
.set("Brake", "CompressorPower", "Converter")
|
||||
.set("Brake", "CompressorStartDelay", CompressorDelay)
|
||||
.set("Cntrl", "CompressorStart", "Automatic")
|
||||
.set("Cntrl", "ConverterStart", "Automatic")
|
||||
.set("Cntrl", "ConverterStartDelay", ConverterDelay);
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("compressor: fed from the converter it waits for the converter start delay") {
|
||||
vehicle loco{generator_vehicle(30.0, 0.0)};
|
||||
REQUIRE(loco->CompressorPower == 2);
|
||||
REQUIRE(loco->ConverterStartDelay == doctest::Approx(30.0));
|
||||
|
||||
loco.run(1.0); // engine off
|
||||
CHECK_FALSE(loco->Power110vIsAvailable);
|
||||
|
||||
loco->Mains = true; // engine started
|
||||
loco.run(25.0);
|
||||
CHECK_FALSE(loco->Power110vIsAvailable);
|
||||
CHECK_FALSE(loco->CompressorFlag);
|
||||
|
||||
loco.run(10.0);
|
||||
CHECK(loco->Power110vIsAvailable);
|
||||
CHECK(loco->CompressorFlag);
|
||||
}
|
||||
|
||||
TEST_CASE("compressor: fed from the converter the start delay counts from the converter voltage") {
|
||||
vehicle loco{generator_vehicle(20.0, 10.0)};
|
||||
REQUIRE(loco->CompressorStartDelay == doctest::Approx(10.0));
|
||||
|
||||
loco.run(1.0); // engine off
|
||||
loco->Mains = true; // engine started
|
||||
loco.run(25.0);
|
||||
REQUIRE(loco->Power110vIsAvailable); // the converter is up
|
||||
CHECK_FALSE(loco->CompressorFlag); // but the compressor waits for its own delay as well
|
||||
|
||||
loco.run(10.0);
|
||||
CHECK(loco->CompressorFlag);
|
||||
}
|
||||
|
||||
158
tests/unit/test_door_closure.cpp
Normal file
158
tests/unit/test_door_closure.cpp
Normal file
@@ -0,0 +1,158 @@
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "scenario.h"
|
||||
#include "vehicle.h"
|
||||
|
||||
// the door closure signalling (SOD, the i-door_blocked lamp of a cab): the state of each vehicle's doors and of the
|
||||
// whole train, the most severe of its vehicles, as the driver gathers it for the lamp (eu07/maszyna#288)
|
||||
|
||||
using test::scenario;
|
||||
using test::definition;
|
||||
using test::vehicle;
|
||||
using namespace test::channels;
|
||||
|
||||
namespace {
|
||||
|
||||
// the state of the whole train, the way TController::determine_consist_state() gathers it
|
||||
door_closure_t consist_closure(scenario &Scenario) {
|
||||
auto closure{door_closure_t::none};
|
||||
for (std::size_t i = 0; i < Scenario.train().size(); ++i) {
|
||||
closure = std::max(closure, Scenario.vehicle(i).door_closure());
|
||||
}
|
||||
return closure;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("door closure: the lamp is lit for locked doors, blinks for released ones and is dark for open ones") {
|
||||
for (auto const lit : {true, false}) {
|
||||
CAPTURE(lit);
|
||||
CHECK(door_closure_lamp(door_closure_t::locked, lit));
|
||||
CHECK(door_closure_lamp(door_closure_t::released, lit) == lit);
|
||||
CHECK_FALSE(door_closure_lamp(door_closure_t::open, lit));
|
||||
CHECK_FALSE(door_closure_lamp(door_closure_t::none, lit));
|
||||
}
|
||||
// a consist takes the most severe state of its vehicles
|
||||
CHECK(std::max(door_closure_t::none, door_closure_t::locked) == door_closure_t::locked);
|
||||
CHECK(std::max(door_closure_t::locked, door_closure_t::released) == door_closure_t::released);
|
||||
CHECK(std::max(door_closure_t::released, door_closure_t::open) == door_closure_t::open);
|
||||
}
|
||||
|
||||
TEST_CASE("door closure: a unit with permits, locked, released by the permit and open, in any of its cars") {
|
||||
scenario scenario{"door closure/elf", motion() + doors()};
|
||||
scenario.add("elf_v1/21we-a", 1).add("elf_v1/21we-b").add("elf_v1/21we-c");
|
||||
scenario.start_up();
|
||||
auto &cab{scenario.cab()};
|
||||
auto &last{scenario.vehicle(scenario.train().size() - 1)};
|
||||
// closed with no permit: no door can be opened
|
||||
CHECK(cab.door_closure() == door_closure_t::locked);
|
||||
CHECK(last.door_closure() == door_closure_t::locked);
|
||||
CHECK(consist_closure(scenario) == door_closure_t::locked);
|
||||
|
||||
scenario.act("permit left");
|
||||
cab.PermitDoors(side::left, true);
|
||||
scenario.wait(2.0);
|
||||
CHECK(last.door_closure() == door_closure_t::released);
|
||||
CHECK(consist_closure(scenario) == door_closure_t::released);
|
||||
|
||||
scenario.act("the last car opens its own door");
|
||||
last.OperateDoors(side::left, true, range_t::local);
|
||||
scenario.wait(5.0);
|
||||
// the cab's own doors stay closed, the train is open all the same
|
||||
CHECK(cab.door_closure() == door_closure_t::released);
|
||||
CHECK(last.door_closure() == door_closure_t::open);
|
||||
CHECK(consist_closure(scenario) == door_closure_t::open);
|
||||
|
||||
scenario.act("close, the steps stay out under the permit");
|
||||
last.OperateDoors(side::left, false, range_t::local);
|
||||
cab.OperateDoors(side::left, false);
|
||||
scenario.wait(10.0);
|
||||
CHECK(last.Doors.instances[side::left].position <= 0.f);
|
||||
// a step out isn't a closed door
|
||||
CHECK(consist_closure(scenario) == door_closure_t::open);
|
||||
|
||||
scenario.act("revoke the permit");
|
||||
cab.PermitDoors(side::left, false);
|
||||
scenario.wait(10.0);
|
||||
CHECK(consist_closure(scenario) == door_closure_t::locked);
|
||||
}
|
||||
|
||||
TEST_CASE("door closure: the doors of a unit without permits are released at a standstill") {
|
||||
scenario scenario{"door closure/en57", motion() + doors()};
|
||||
scenario.add("en57_v1/5bgaiii_led_spot", 1).add("en57_v1/6ba_840").add("en57_v1/5bgb");
|
||||
scenario.start_up();
|
||||
auto &cab{scenario.cab()};
|
||||
auto &middle{scenario.vehicle(1)};
|
||||
REQUIRE_FALSE(cab.Doors.permit_needed);
|
||||
REQUIRE(middle.Doors.permit_needed);
|
||||
// the door lock engages only once the train runs (DoorLockSpeed), till then the end cars' doors can be opened
|
||||
CHECK(cab.door_closure() == door_closure_t::released);
|
||||
CHECK(middle.door_closure() == door_closure_t::locked);
|
||||
CHECK(consist_closure(scenario) == door_closure_t::released);
|
||||
scenario.act("open right");
|
||||
cab.OperateDoors(side::right, true);
|
||||
scenario.wait(10.0);
|
||||
CHECK(consist_closure(scenario) == door_closure_t::open);
|
||||
scenario.act("close right");
|
||||
cab.OperateDoors(side::right, false);
|
||||
scenario.wait(10.0);
|
||||
CHECK(consist_closure(scenario) == door_closure_t::released);
|
||||
}
|
||||
|
||||
TEST_CASE("door closure: a locomotive has no doors to signal, its coach does") {
|
||||
scenario scenario{"door closure/eu07 with a coach", motion() + doors()};
|
||||
scenario.add("4e_v1/4e", 1).add("bdhpumn_v3/bdhpumn");
|
||||
scenario.start_up();
|
||||
CHECK(scenario.cab().door_closure() == door_closure_t::none);
|
||||
scenario.act("open right");
|
||||
scenario.cab().PermitDoors(side::right, true);
|
||||
scenario.cab().OperateDoors(side::right, true);
|
||||
scenario.wait(10.0);
|
||||
CHECK(scenario.vehicle(1).door_closure() == door_closure_t::open);
|
||||
CHECK(consist_closure(scenario) == door_closure_t::open);
|
||||
}
|
||||
|
||||
TEST_CASE("door closure: the signalling is switched on by DoorClosureSignal in the Doors section, off without it") {
|
||||
SUBCASE("without the key") {
|
||||
vehicle wagon{definition::load("wagon")};
|
||||
CHECK_FALSE(wagon->Doors.closure_signal);
|
||||
}
|
||||
SUBCASE("with the key") {
|
||||
vehicle wagon{definition::load("wagon").set("Doors", "DoorClosureSignal", "Yes")};
|
||||
CHECK(wagon->Doors.closure_signal);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("door closure: without DoorClosureSignal the lamp shows the lock of the vehicle's own doors, as before") {
|
||||
vehicle wagon{definition::load("wagon")};
|
||||
REQUIRE_FALSE(wagon->Doors.closure_signal);
|
||||
for (auto const locked : {true, false}) {
|
||||
wagon->Doors.is_locked = locked;
|
||||
for (auto const consist : {door_closure_t::none, door_closure_t::locked, door_closure_t::released, door_closure_t::open}) {
|
||||
for (auto const lit : {true, false}) {
|
||||
CAPTURE(locked);
|
||||
CAPTURE(static_cast<int>(consist));
|
||||
CAPTURE(lit);
|
||||
// no blinking at a standstill with the doors closed, whatever the consist does
|
||||
CHECK(wagon->door_closure_lamp_lit(consist, lit) == locked);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("door closure: with DoorClosureSignal the lamp shows the consist in three states") {
|
||||
vehicle wagon{definition::load("wagon").set("Doors", "DoorClosureSignal", "Yes")};
|
||||
REQUIRE(wagon->Doors.closure_signal);
|
||||
for (auto const locked : {true, false}) {
|
||||
// the vehicle's own lock doesn't matter, the consist does
|
||||
wagon->Doors.is_locked = locked;
|
||||
for (auto const lit : {true, false}) {
|
||||
CAPTURE(locked);
|
||||
CAPTURE(lit);
|
||||
CHECK(wagon->door_closure_lamp_lit(door_closure_t::locked, lit));
|
||||
CHECK(wagon->door_closure_lamp_lit(door_closure_t::released, lit) == lit);
|
||||
CHECK_FALSE(wagon->door_closure_lamp_lit(door_closure_t::open, lit));
|
||||
CHECK_FALSE(wagon->door_closure_lamp_lit(door_closure_t::none, lit));
|
||||
}
|
||||
}
|
||||
}
|
||||
74
tests/unit/test_engine_shutdown.cpp
Normal file
74
tests/unit/test_engine_shutdown.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#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->CabOccupied = 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->Mains);
|
||||
CHECK(shunter->FuelPump.is_active);
|
||||
CHECK(shunter->enrot > 0.9 * shunter->dizel_nmin);
|
||||
}
|
||||
|
||||
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->Mains);
|
||||
shunter->BatterySwitch(false);
|
||||
shunter.run(10.0);
|
||||
CHECK(shunter->Power110vIsAvailable); // the converter run by the engine keeps feeding the fuel pump
|
||||
CHECK(shunter->Mains);
|
||||
CHECK(shunter->enrot > 0.9 * shunter->dizel_nmin);
|
||||
}
|
||||
|
||||
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->Mains);
|
||||
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->Mains);
|
||||
CHECK(shunter->enrot > 0.9 * shunter->dizel_nmin);
|
||||
}
|
||||
|
||||
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());
|
||||
}
|
||||
@@ -57,3 +57,74 @@ TEST_CASE("line contactors: the ground relay and overload lamps follow the same
|
||||
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->Mains);
|
||||
REQUIRE_FALSE(vehicle->ControlPressureSwitch);
|
||||
CHECK_FALSE(vehicle->StLinFlag);
|
||||
CHECK(vehicle->LineContactorsLampLit());
|
||||
|
||||
vehicle->IncMainCtrl(1);
|
||||
vehicle.run(3.0);
|
||||
CHECK(vehicle->StLinFlag);
|
||||
CHECK_FALSE(vehicle->LineContactorsLampLit());
|
||||
|
||||
vehicle->DecMainCtrl(1);
|
||||
vehicle.run(3.0);
|
||||
CHECK_FALSE(vehicle->StLinFlag);
|
||||
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->StLinFlag);
|
||||
|
||||
vehicle.hold_brake_pipe(2.5); // bar, below the 3.6 bar of the pressure switch
|
||||
vehicle.run(10.0);
|
||||
REQUIRE(vehicle->ControlPressureSwitch);
|
||||
CHECK_FALSE(vehicle->StLinFlag);
|
||||
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->ControlPressureSwitch);
|
||||
CHECK_FALSE(vehicle->StLinFlag);
|
||||
CHECK(vehicle->LineContactorsLampLit());
|
||||
vehicle->DecMainCtrl(1);
|
||||
vehicle.run(3.0);
|
||||
CHECK(vehicle->StLinFlag);
|
||||
CHECK_FALSE(vehicle->LineContactorsLampLit());
|
||||
}
|
||||
|
||||
114
tests/unit/test_linebreaker.cpp
Normal file
114
tests/unit/test_linebreaker.cpp
Normal file
@@ -0,0 +1,114 @@
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "consist.h"
|
||||
#include "drive.h"
|
||||
|
||||
#include "vehicle/linebreaker.h"
|
||||
|
||||
// the line breaker (WS) controls of the cab (eu07/maszyna#394)
|
||||
|
||||
using test::consist;
|
||||
using test::definition;
|
||||
|
||||
namespace {
|
||||
|
||||
// the line breaker lever of the EP05 (main_sw), a single two-state lever, the way TTrain works it: the state
|
||||
// the cab keeps of the line breaker follows the vehicle, the breaker closes while the lever is on and can close
|
||||
struct lever {
|
||||
TMoverParameters &mover;
|
||||
int breaker{0}; // as TTrain::m_linebreakerstate: 0 open, 1 closed
|
||||
bool on{false};
|
||||
|
||||
void press() {
|
||||
switch (linebreaker::pressed(breaker, true, on)) {
|
||||
case linebreaker::toggle::close:
|
||||
on = true;
|
||||
break;
|
||||
case linebreaker::toggle::open:
|
||||
on = false;
|
||||
if (breaker == 1 && mover.MainSwitch(false)) {
|
||||
breaker = 0;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
// TTrain::Update()
|
||||
void update() {
|
||||
if (breaker == 0 && mover.Mains) {
|
||||
breaker = 1;
|
||||
}
|
||||
if (breaker == 1 && false == mover.Mains) {
|
||||
breaker = 0;
|
||||
}
|
||||
if (on && breaker == 0 && mover.MainSwitchCheck()) {
|
||||
breaker = mover.MainSwitch(true) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("line breaker: a press of the toggle closes an open breaker and opens a closed one") {
|
||||
using enum linebreaker::toggle;
|
||||
for (auto const latching : {false, true}) {
|
||||
CHECK(linebreaker::pressed(0, latching, false) == close);
|
||||
CHECK(linebreaker::pressed(1, latching, true) == open);
|
||||
CHECK(linebreaker::pressed(1, latching, false) == open);
|
||||
// freshly closed, the cab finishes closing it first
|
||||
CHECK(linebreaker::pressed(2, latching, true) == none);
|
||||
}
|
||||
// a lever left on over an open breaker goes off; push buttons have no position to keep
|
||||
CHECK(linebreaker::pressed(0, true, true) == open);
|
||||
CHECK(linebreaker::pressed(0, false, true) == close);
|
||||
}
|
||||
|
||||
TEST_CASE("line breaker: the EP05's lever goes off with the converter overload relay tripped (eu07/maszyna#394)") {
|
||||
consist train;
|
||||
auto &ep05{train.add(definition::fiz("ep05_v2/ep05"), 1).mover()};
|
||||
test::track const line{0.15, 0.0, test::catenary_3kv};
|
||||
auto const driver{test::driving(train)};
|
||||
REQUIRE(test::start_up(driver, line));
|
||||
REQUIRE(ep05.Mains);
|
||||
REQUIRE(ep05.ConverterFlag);
|
||||
lever ws{ep05, 1, true};
|
||||
|
||||
// the converter overload relay knocks the line breaker out, as the cab does it when the converter is
|
||||
// switched on together with the compressor; the lever stays on
|
||||
ep05.ConvOvldFlag = true;
|
||||
ep05.MainSwitch(false, range_t::local);
|
||||
ws.update();
|
||||
REQUIRE_FALSE(ep05.Mains);
|
||||
REQUIRE(ws.breaker == 0);
|
||||
CHECK(ws.on);
|
||||
// with the relay tripped the breaker doesn't close
|
||||
test::drive(driver, line, 5.0);
|
||||
CHECK_FALSE(ep05.MainSwitchCheck());
|
||||
|
||||
// nothing holds the lever: it goes off, and on again, though the breaker stays open
|
||||
ws.press();
|
||||
CHECK_FALSE(ws.on);
|
||||
ws.press();
|
||||
CHECK(ws.on);
|
||||
ws.update();
|
||||
CHECK_FALSE(ep05.Mains);
|
||||
ws.press();
|
||||
CHECK_FALSE(ws.on);
|
||||
|
||||
// the relay reset, with the converter switched off, the lever put on closes the breaker again
|
||||
ep05.ConverterSwitch(false, range_t::local);
|
||||
test::drive(driver, line, 1.0);
|
||||
CHECK(ep05.RelayReset(relay_t::primaryconverteroverload, range_t::local));
|
||||
CHECK_FALSE(ep05.ConvOvldFlag);
|
||||
ws.update();
|
||||
CHECK_FALSE(ep05.Mains); // the lever is off
|
||||
ws.press();
|
||||
ws.update();
|
||||
CHECK(ep05.Mains);
|
||||
CHECK(ws.breaker == 1);
|
||||
// and the next press opens it
|
||||
ws.press();
|
||||
CHECK_FALSE(ws.on);
|
||||
CHECK_FALSE(ep05.Mains);
|
||||
}
|
||||
55
tests/unit/test_oil_pump.cpp
Normal file
55
tests/unit/test_oil_pump.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
#include "vehicle.h"
|
||||
|
||||
using test::definition;
|
||||
using test::vehicle;
|
||||
|
||||
// the oil pump lamp of the cab (i-oilpump) shows OilPump.is_active: the pre-lubrication pump of 401Da, which works
|
||||
// before the engine start and stops once the engine runs and makes the oil pressure itself (eu07/maszyna#546)
|
||||
// NOTE: the test vehicle has no diesel engine, so the pump check is called the way dizel_Update() calls it
|
||||
|
||||
TEST_CASE("oil pump: the pre-lubrication pump works before the engine start and stops once the engine runs") {
|
||||
vehicle loco{definition::load("cab_vehicle").set("Cntrl", "OilStart", "Manual")};
|
||||
REQUIRE(loco->OilPump.start_type == start_t::manual);
|
||||
loco->Power24vIsAvailable = true; // battery on
|
||||
|
||||
loco->OilPumpCheck(0.01);
|
||||
CHECK_FALSE(loco->OilPump.is_active); // not switched on yet
|
||||
|
||||
loco->OilPump.is_enabled = true; // pump switch on: pre-lubrication
|
||||
loco->OilPumpCheck(0.01);
|
||||
CHECK(loco->OilPump.is_active);
|
||||
|
||||
loco->Mains = true; // engine started
|
||||
loco->OilPumpCheck(0.01);
|
||||
CHECK_FALSE(loco->OilPump.is_active);
|
||||
}
|
||||
|
||||
TEST_CASE("oil pump: the pump started with the engine start procedure stops once the engine runs") {
|
||||
vehicle loco{definition::load("cab_vehicle").set("Cntrl", "OilStart", "Automatic")};
|
||||
REQUIRE(loco->OilPump.start_type == start_t::automatic);
|
||||
loco->Power24vIsAvailable = true;
|
||||
|
||||
loco->dizel_startup = true; // starter button pressed
|
||||
loco->OilPumpCheck(0.01);
|
||||
CHECK(loco->OilPump.is_active);
|
||||
|
||||
loco->dizel_startup = false; // start procedure done, the pump keeps working until the engine runs
|
||||
loco->OilPumpCheck(0.01);
|
||||
CHECK(loco->OilPump.is_active);
|
||||
|
||||
loco->Mains = true;
|
||||
loco->OilPumpCheck(0.01);
|
||||
CHECK_FALSE(loco->OilPump.is_active);
|
||||
}
|
||||
|
||||
TEST_CASE("oil pump: without power the pump and its lamp stay off") {
|
||||
vehicle loco{definition::load("cab_vehicle")};
|
||||
loco->Power24vIsAvailable = false;
|
||||
loco->Power110vIsAvailable = false;
|
||||
|
||||
loco->OilPump.is_enabled = true;
|
||||
loco->OilPumpCheck(0.01);
|
||||
CHECK_FALSE(loco->OilPump.is_active);
|
||||
}
|
||||
268
tests/unit/test_test_mode.cpp
Normal file
268
tests/unit/test_test_mode.cpp
Normal file
@@ -0,0 +1,268 @@
|
||||
#include "stdafx.h"
|
||||
#include "doctest.h"
|
||||
|
||||
#include "simulation/simulationtestrules.h"
|
||||
|
||||
#include <array>
|
||||
#include <exception>
|
||||
#include <new>
|
||||
#include <stdexcept>
|
||||
#include <vector>
|
||||
|
||||
// the test mode of the simulator (eu07 --test, eu07/maszyna#541): its exit codes, command line and end conditions
|
||||
|
||||
namespace {
|
||||
|
||||
using simulation::test_result;
|
||||
|
||||
simulation::test_command_line parse(std::vector<char const *> Arguments)
|
||||
{
|
||||
Arguments.insert(Arguments.begin(), "eu07");
|
||||
return simulation::parse_test_command_line(Arguments);
|
||||
}
|
||||
|
||||
// a frame of the default 0.03 s
|
||||
simulation::test_frame frame(bool const Atrest, std::optional<double> const Reported = std::nullopt, std::string_view const Reason = {})
|
||||
{
|
||||
return simulation::test_frame{0.03, Reported, Reason, Atrest};
|
||||
}
|
||||
|
||||
// runs frames until the test ends or Seconds of simulation time go by
|
||||
std::optional<simulation::test_verdict> run(simulation::test_progress &Progress, simulation::test_limits const &Limits, double const Seconds,
|
||||
simulation::test_frame const &Frame)
|
||||
{
|
||||
while (Progress.time < Seconds)
|
||||
{
|
||||
if (auto verdict{simulation::evaluate_frame(Progress, Frame, Limits)})
|
||||
return verdict;
|
||||
}
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
TEST_CASE("test mode: the exit codes keep clear of the ones of a killed or aborted process")
|
||||
{
|
||||
std::array const results{test_result::pass, test_result::fail, test_result::signal_passed_at_danger, test_result::timeout, test_result::standstill, test_result::error};
|
||||
for (auto const result : results)
|
||||
{
|
||||
auto const code{static_cast<int>(result)};
|
||||
CAPTURE(code);
|
||||
CHECK(code != 1); // TerminateProcess, most programs' failure
|
||||
CHECK(code != 3); // abort() on Windows
|
||||
CHECK(code < 126); // shells, signals on Linux
|
||||
CHECK(simulation::to_string(result) != "unknown");
|
||||
}
|
||||
// the codes are public: scripts and CI read them
|
||||
CHECK(static_cast<int>(test_result::pass) == 0);
|
||||
CHECK(static_cast<int>(test_result::fail) == 10);
|
||||
CHECK(static_cast<int>(test_result::signal_passed_at_danger) == 11);
|
||||
CHECK(static_cast<int>(test_result::timeout) == 12);
|
||||
CHECK(static_cast<int>(test_result::standstill) == 13);
|
||||
CHECK(static_cast<int>(test_result::error) == 14);
|
||||
}
|
||||
|
||||
TEST_CASE("test mode: seconds on the command line are a number, not negative")
|
||||
{
|
||||
CHECK(simulation::parse_seconds("240").value_or(-1.0) == doctest::Approx(240.0));
|
||||
CHECK(simulation::parse_seconds("0.5").value_or(-1.0) == doctest::Approx(0.5));
|
||||
CHECK(simulation::parse_seconds("0").value_or(-1.0) == doctest::Approx(0.0));
|
||||
CHECK_FALSE(simulation::parse_seconds("").has_value());
|
||||
CHECK_FALSE(simulation::parse_seconds("-1").has_value());
|
||||
CHECK_FALSE(simulation::parse_seconds("60s").has_value());
|
||||
CHECK_FALSE(simulation::parse_seconds("abc").has_value());
|
||||
CHECK_FALSE(simulation::parse_seconds("inf").has_value());
|
||||
CHECK_FALSE(simulation::parse_seconds("nan").has_value());
|
||||
}
|
||||
|
||||
TEST_CASE("test mode: the command line")
|
||||
{
|
||||
SUBCASE("without --test there is no test")
|
||||
{
|
||||
auto const commandline{parse({"-s", "td.scn", "-v", "ep07-424"})};
|
||||
CHECK_FALSE(commandline.enabled);
|
||||
CHECK(commandline.error.empty());
|
||||
}
|
||||
SUBCASE("--test and its limits, in any order")
|
||||
{
|
||||
auto const commandline{parse({"--test-wall-timeout", "900", "-s", "td.scn", "--test", "--test-timeout", "240"})};
|
||||
CHECK(commandline.enabled);
|
||||
CHECK(commandline.timeout.value_or(-1.0) == doctest::Approx(240.0));
|
||||
CHECK(commandline.wall_timeout.value_or(-1.0) == doctest::Approx(900.0));
|
||||
CHECK(commandline.error.empty());
|
||||
}
|
||||
SUBCASE("a limit not given stays unset")
|
||||
{
|
||||
auto const commandline{parse({"--test", "-s", "td.scn"})};
|
||||
CHECK_FALSE(commandline.timeout.has_value());
|
||||
CHECK_FALSE(commandline.wall_timeout.has_value());
|
||||
}
|
||||
SUBCASE("a limit which isn't a number is an error, not a limit turned off")
|
||||
{
|
||||
auto const commandline{parse({"--test", "-s", "td.scn", "--test-timeout", "4m"})};
|
||||
CHECK(commandline.enabled);
|
||||
CHECK_FALSE(commandline.timeout.has_value());
|
||||
CHECK(commandline.error == "--test-timeout needs a number of seconds");
|
||||
}
|
||||
SUBCASE("a limit without its value is an error")
|
||||
{
|
||||
auto const commandline{parse({"--test", "-s", "td.scn", "--test-wall-timeout"})};
|
||||
CHECK(commandline.error == "--test-wall-timeout needs a number of seconds");
|
||||
}
|
||||
SUBCASE("the first error is the one told")
|
||||
{
|
||||
auto const commandline{parse({"--test", "--test-timeout", "x", "--test-wall-timeout", "y"})};
|
||||
CHECK(commandline.error == "--test-timeout needs a number of seconds");
|
||||
}
|
||||
SUBCASE("values of other options aren't taken for options")
|
||||
{
|
||||
auto const commandline{parse({"-s", "--test", "-ini", "--test-timeout", "-v", "--test-wall-timeout", "-seed", "--test"})};
|
||||
CHECK_FALSE(commandline.enabled);
|
||||
CHECK(commandline.error.empty());
|
||||
}
|
||||
SUBCASE("-edit takes no option for its scenery, which is optional")
|
||||
{
|
||||
// a scenery after -edit or none: the option after it is read either way
|
||||
CHECK(parse({"-edit", "--test", "-s", "td.scn"}).enabled);
|
||||
CHECK(parse({"-edit", "td.scn", "--test"}).enabled);
|
||||
// -edit leaves -s alone, which takes --test for its scenery, as the simulator reads it
|
||||
CHECK_FALSE(parse({"-edit", "-s", "--test"}).enabled);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("test mode: the real time limit")
|
||||
{
|
||||
SUBCASE("given, it is the limit, 0 turns it off")
|
||||
{
|
||||
CHECK(simulation::wall_clock_limit(120.0, 3600.0) == doctest::Approx(120.0));
|
||||
CHECK(simulation::wall_clock_limit(0.0, 3600.0) == doctest::Approx(0.0));
|
||||
}
|
||||
SUBCASE("not given, it is the simulation time limit and time for the loading")
|
||||
{
|
||||
CHECK(simulation::wall_clock_limit(std::nullopt, 240.0) == doctest::Approx(240.0 + simulation::wall_timeout_loading_allowance));
|
||||
CHECK(simulation::wall_clock_limit(std::nullopt, 3600.0) == doctest::Approx(3600.0 + simulation::wall_timeout_loading_allowance));
|
||||
}
|
||||
SUBCASE("no simulation time limit, no real time limit unless given")
|
||||
{
|
||||
CHECK(simulation::wall_clock_limit(std::nullopt, 0.0) == doctest::Approx(0.0));
|
||||
CHECK(simulation::wall_clock_limit(300.0, 0.0) == doctest::Approx(300.0));
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("test mode: the end conditions")
|
||||
{
|
||||
simulation::test_limits limits;
|
||||
simulation::test_progress progress;
|
||||
|
||||
SUBCASE("nothing happens, nothing ends")
|
||||
{
|
||||
CHECK_FALSE(simulation::evaluate_frame(progress, frame(false), limits).has_value());
|
||||
CHECK(progress.time == doctest::Approx(0.03));
|
||||
CHECK(progress.resttime == doctest::Approx(0.0));
|
||||
}
|
||||
SUBCASE("a cell nobody wrote to says nothing")
|
||||
{
|
||||
CHECK_FALSE(simulation::evaluate_frame(progress, frame(false, -1.0), limits).has_value());
|
||||
CHECK_FALSE(simulation::evaluate_frame(progress, frame(false, 2.0), limits).has_value());
|
||||
CHECK_FALSE(progress.passrequested);
|
||||
}
|
||||
SUBCASE("0 fails at once, with the text of the cell")
|
||||
{
|
||||
auto const verdict{simulation::evaluate_frame(progress, frame(false, 0.0, "wrong_track"), limits)};
|
||||
REQUIRE(verdict.has_value());
|
||||
CHECK(verdict->result == test_result::fail);
|
||||
CHECK(verdict->reason == "__test.result set to 0 (wrong_track)");
|
||||
}
|
||||
SUBCASE("1 passes once the tested trains have stood for a second")
|
||||
{
|
||||
CHECK_FALSE(simulation::evaluate_frame(progress, frame(false, 1.0), limits).has_value());
|
||||
CHECK(progress.passrequested);
|
||||
// still moving: the pass waits
|
||||
CHECK_FALSE(run(progress, limits, 30.0, frame(false, 1.0)).has_value());
|
||||
auto const stoppedat{progress.time};
|
||||
auto const verdict{run(progress, limits, 60.0, frame(true, 1.0))};
|
||||
REQUIRE(verdict.has_value());
|
||||
CHECK(verdict->result == test_result::pass);
|
||||
CHECK(progress.time - stoppedat == doctest::Approx(simulation::pass_settle_time).epsilon(0.05));
|
||||
}
|
||||
SUBCASE("the pass stays requested when the cell changes back")
|
||||
{
|
||||
CHECK_FALSE(simulation::evaluate_frame(progress, frame(false, 1.0), limits).has_value());
|
||||
auto const verdict{run(progress, limits, 60.0, frame(true, -1.0))};
|
||||
REQUIRE(verdict.has_value());
|
||||
CHECK(verdict->result == test_result::pass);
|
||||
}
|
||||
SUBCASE("1 with test.no_movement_before_pass no passes at once")
|
||||
{
|
||||
limits.no_movement_before_pass = false;
|
||||
auto const verdict{simulation::evaluate_frame(progress, frame(false, 1.0, "reached_the_stop"), limits)};
|
||||
REQUIRE(verdict.has_value());
|
||||
CHECK(verdict->result == test_result::pass);
|
||||
CHECK(verdict->reason == "__test.result set to 1 (reached_the_stop)");
|
||||
}
|
||||
SUBCASE("standing still without a result ends after test.standstill")
|
||||
{
|
||||
limits.standstill = 120.0;
|
||||
auto const verdict{run(progress, limits, 1000.0, frame(true))};
|
||||
REQUIRE(verdict.has_value());
|
||||
CHECK(verdict->result == test_result::standstill);
|
||||
CHECK(progress.time == doctest::Approx(120.0).epsilon(0.001));
|
||||
}
|
||||
SUBCASE("a move starts the standstill over")
|
||||
{
|
||||
limits.standstill = 120.0;
|
||||
CHECK_FALSE(run(progress, limits, 100.0, frame(true)).has_value());
|
||||
CHECK_FALSE(simulation::evaluate_frame(progress, frame(false), limits).has_value());
|
||||
CHECK(progress.resttime == doctest::Approx(0.0));
|
||||
CHECK_FALSE(run(progress, limits, 200.0, frame(true)).has_value());
|
||||
}
|
||||
SUBCASE("test.pass_on_standstill makes the standstill a pass")
|
||||
{
|
||||
limits.standstill = 10.0;
|
||||
limits.pass_on_standstill = true;
|
||||
auto const verdict{run(progress, limits, 1000.0, frame(true))};
|
||||
REQUIRE(verdict.has_value());
|
||||
CHECK(verdict->result == test_result::pass);
|
||||
}
|
||||
SUBCASE("test.standstill 0 never ends the test")
|
||||
{
|
||||
limits.standstill = 0.0;
|
||||
limits.timeout = 0.0;
|
||||
CHECK_FALSE(run(progress, limits, 5000.0, frame(true)).has_value());
|
||||
}
|
||||
SUBCASE("no result by test.timeout")
|
||||
{
|
||||
limits.timeout = 240.0;
|
||||
auto const verdict{run(progress, limits, 1000.0, frame(false))};
|
||||
REQUIRE(verdict.has_value());
|
||||
CHECK(verdict->result == test_result::timeout);
|
||||
CHECK(verdict->reason == "no result after 240 s");
|
||||
CHECK(progress.time == doctest::Approx(240.0).epsilon(0.001));
|
||||
}
|
||||
SUBCASE("a result in the last frame wins over the timeout")
|
||||
{
|
||||
limits.timeout = 0.03;
|
||||
auto const verdict{simulation::evaluate_frame(progress, frame(false, 0.0), limits)};
|
||||
REQUIRE(verdict.has_value());
|
||||
CHECK(verdict->result == test_result::fail);
|
||||
}
|
||||
}
|
||||
|
||||
TEST_CASE("test mode: what ended a run the simulator didn't end")
|
||||
{
|
||||
SUBCASE("an exception says what it was")
|
||||
{
|
||||
CHECK(simulation::describe_exception(std::make_exception_ptr(std::runtime_error("no scenery"))) == "critical error: no scenery");
|
||||
// e.g. std::stof on a token of a scenery which isn't a number
|
||||
CHECK(simulation::describe_exception(std::make_exception_ptr(std::invalid_argument("stof"))) == "critical error: stof");
|
||||
CHECK(simulation::describe_exception(std::make_exception_ptr(std::bad_alloc())).starts_with("critical error: "));
|
||||
}
|
||||
SUBCASE("something thrown which isn't a std::exception")
|
||||
{
|
||||
CHECK(simulation::describe_exception(std::make_exception_ptr(42)) == "critical error: an exception of unknown type");
|
||||
}
|
||||
SUBCASE("terminated without an exception")
|
||||
{
|
||||
CHECK(simulation::describe_exception(nullptr) == "the simulator was terminated");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user