18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 09:27:10 +01:00
Files
maszyna/tests/unit/test_loads.cpp
T
Hirek 5e56a91515 refactor(physics): the devices out of physics::Vehicle, the pantographs as components
The types of the devices nested in physics::Vehicle (basic_device, the pumps,
the fans, basic_valve, basic_pantograph, basic_door, door_data, water_heater,
genset_device) move out of it into physics/components/devices.h, namespace
physics, so the components of the vehicle can hold them.

The pantographs and their air become components, with English names
(physics/components/pantographs.h):

  Pantographs                 pantographs (ByEnd<basic_pantograph>)
  pantographCircuit           PantFrontVolt / PantRearVolt frontVoltage /
                              rearVoltage, PantographVoltage supplyVoltage,
                              PantAllDown allDown, PantSwitchType switchType,
                              PantsPreset presets
  pantographAir               PantVolume volume, PantPress pressure,
                              PantCompFlag compressorRunning,
                              PantographCompressorStart compressorStart,
                              SmallCompressorPower compressorPower, PantsValve
                              valve, bPantKurek3 connectedToMainReservoir,
                              PantAutoValve autoValve, PantPressSwitchActive /
                              PantPressLockActive pressureSwitchActive /
                              pressureLockActive

No string literal changed (checked over all the changed files).

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
2026-11-29 02:13:17 +01:00

117 lines
5.0 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
// characterisation of the loads of vehicles besides the loading by commands (test_commands.cpp): the load
// assigned to a vehicle (AssignLoad), with the pantographs of an electric vehicle set up by the "pantstate"
// load of a scenario, and the steps of loading and unloading (LoadingDone)
using test::definition;
using test::vehicle;
TEST_CASE("loads: the pantographs of an electric vehicle set up by the amount of its pantstate load") {
// bit 0 raises the front pantograph, bit 1 the rear one, bit 2 turns the vehicle round in the train first
// (DoubleTr), so the bits name the pantographs the other way round
struct setup {
int amount;
bool frontraised;
bool rearraised;
};
for (auto const &[amount, frontraised, rearraised] : {setup{0, false, false}, setup{1, true, false}, setup{2, false, true}, setup{3, true, true}, setup{5, false, true},
setup{6, true, false}}) {
CAPTURE(amount);
vehicle et42{definition::fiz("et42_v2/112e-a")};
CHECK(et42->AssignLoad("pantstate", static_cast<float>(amount)));
CHECK(et42->DoubleTr == ((amount & 4) != 0 ? -1 : 1));
CHECK(et42->pantographs[VehicleEnd::front].valve.is_enabled == frontraised);
CHECK(et42->pantographs[VehicleEnd::rear].valve.is_enabled == rearraised);
// the load itself stays as it was
CHECK(et42->LoadAmount == doctest::Approx(0.0));
}
// a vehicle without a current collector takes no such load
vehicle wagon{definition::fiz("3wl_v2/3wl")};
CHECK_FALSE(wagon->AssignLoad("pantstate", 3.f));
}
TEST_CASE("loads: a load assigned, of one kind at a time, up to the vehicle's capacity, and emptied") {
vehicle wagon{definition::fiz("3wl_v2/3wl")};
auto const empty{wagon->TotalMass};
REQUIRE(wagon->AssignLoad("coal", 10.f));
CHECK(wagon->LoadTypeChange);
CHECK(wagon->LoadType.name == "coal");
CHECK(wagon->TotalMass > empty);
// more of the same: the amount set, not added, and no more than the vehicle takes
wagon->LoadTypeChange = false;
REQUIRE(wagon->AssignLoad("coal", 1000.f));
CHECK_FALSE(wagon->LoadTypeChange);
CHECK(wagon->LoadAmount == doctest::Approx(wagon->MaxLoad));
// another kind can't be added to a load, nor can an unknown one be loaded
CHECK_FALSE(wagon->AssignLoad("ruda", 5.f));
CHECK(wagon->LoadType.name == "coal");
// emptied, with no name
REQUIRE(wagon->AssignLoad(""));
CHECK(wagon->LoadTypeChange);
CHECK(wagon->LoadAmount == doctest::Approx(0.0));
CHECK(wagon->LoadType.name.empty());
CHECK_FALSE(wagon->AssignLoad("unknown", 5.f));
CHECK(wagon->AssignLoad("ruda", 5.f));
}
TEST_CASE("loads: the steps of loading and unloading") {
// most of the game's wagons may be overloaded (OverLoadFactor), the 3WL not
vehicle wagon{definition::fiz("3wl_v2/3wl").set("Load", "OverLoadFactor", 1.5)};
REQUIRE(wagon->AssignLoad("coal", 10.f));
auto const capacity{wagon->MaxLoad * (1.0 + wagon->OverLoadFactor)};
SUBCASE("no speed of the change: done at once") {
CHECK(wagon->LoadingDone(0.0, "coal"));
CHECK(wagon->LoadStatus == 4);
}
SUBCASE("no load, or another one, named: done when it was") {
wagon->LoadStatus = 1;
CHECK_FALSE(wagon->LoadingDone(1.0, ""));
CHECK_FALSE(wagon->LoadingDone(1.0, "ruda"));
wagon->LoadStatus = 4;
CHECK(wagon->LoadingDone(1.0, ""));
}
SUBCASE("unloading, step by step, what was asked or all of it, the name going with the last of it") {
wagon->CommandIn.Value1 = 4.0; // asked to unload
wagon->LastLoadChangeTime = 2.0; // at 1 a second
CHECK_FALSE(wagon->LoadingDone(-1.0, "coal"));
CHECK(wagon->LoadStatus == 2);
CHECK(wagon->LoadAmount == doctest::Approx(8.0));
CHECK(wagon->LastLoadChangeTime == doctest::Approx(0.0));
// nothing done since the last step
CHECK_FALSE(wagon->LoadingDone(-1.0, "coal"));
CHECK(wagon->LoadAmount == doctest::Approx(8.0));
wagon->LastLoadChangeTime = 2.0;
CHECK(wagon->LoadingDone(-1.0, "coal"));
CHECK(wagon->LoadAmount == doctest::Approx(6.0));
wagon->CommandIn.Value1 = 100.0;
wagon->LastLoadChangeTime = 10.0;
CHECK(wagon->LoadingDone(-1.0, "coal"));
CHECK(wagon->LoadAmount == doctest::Approx(0.0));
CHECK(wagon->LoadType.name.empty());
}
SUBCASE("loading, step by step, up to what was asked or what the vehicle takes, slower when overloaded") {
wagon->CommandIn.Value1 = 5.0;
wagon->LastLoadChangeTime = 2.0;
CHECK_FALSE(wagon->LoadingDone(1.0, "coal"));
CHECK(wagon->LoadStatus == 1);
CHECK(wagon->LoadAmount == doctest::Approx(12.0));
wagon->LastLoadChangeTime = 3.0;
CHECK(wagon->LoadingDone(1.0, "coal"));
CHECK(wagon->LoadAmount == doctest::Approx(15.0));
wagon->CommandIn.Value1 = 1000.0;
wagon->LastLoadChangeTime = 1000.0;
CHECK(wagon->LoadingDone(1.0, "coal"));
CHECK(wagon->LoadAmount == doctest::Approx(capacity));
CHECK(capacity == doctest::Approx(2.5 * wagon->MaxLoad));
// over the vehicle's own capacity, the change goes at half the speed
wagon->CommandIn.Value1 = 1000.0;
wagon->LastLoadChangeTime = 4.0;
CHECK_FALSE(wagon->LoadingDone(-1.0, "coal"));
CHECK(wagon->LoadAmount == doctest::Approx(capacity - 2.0));
}
}