mirror of
https://github.com/MaSzyna-EU07/maszyna.git
synced 2026-11-19 08:46:00 +01:00
Merge remote-tracking branch 'origin/master' into fix/door-inner-faces-lowpoly-lighting
# Conflicts: # vehicle/DynObj.cpp
This commit is contained in:
@@ -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));
|
||||
}
|
||||
}
|
||||
}
|
||||
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