17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-18 10:19:20 +02:00
Files
maszyna/tests/unit/test_compressor.cpp
jerrrrycho ec345f94cb fix: automatic coupler crashes, horns, compressor start delay, radio and cab lever sounds
- automatic couplers don't catch above the safe collision speed (#86): with crash damage on they couple at a
  closing speed of 15 km/h at most, a faster hit locks the coupling until the vehicles part and the collision
  runs its course. On the way: CollisionVelocity() read a head-on 10 + 10 km/h as 14.1 km/h (quaternions turn
  by half the angle), it's now taken from the touching ends; CollisionDetect() took the other vehicle's speed
  the wrong way round for vehicles facing each other. Head-on hits now derail sooner, at the intended limit,
- a single horn lever can't sound both tones at once (eu07/maszyna#392),
- a skid ends once the vehicle stops on locked wheels (eu07/maszyna#479),
- electronic destination signs are blanked at the end of the timetable (eu07/maszyna#446),
- horns need the air or the voltage to sound (eu07/maszyna#290, #76): HornType=[Pneumatic]|Electric and
  Horn3Type in Cntrl.; a pneumatic horn needs 0.2 MPa in the main reservoir (or the main pipe without one),
  an electric one the low voltage; the lever stays where it was put,
- compressor start delay (#67): CompressorStartDelay [s] in Brake., counted from the compressor getting its
  power, after the engine starts say; none by default,
- the channel and volume buttons of a radio without power do nothing (eu07/maszyna#429); the power check of
  the radio is TMoverParameters::RadioPowered(),
- a lever moved smoothly sounds the positions it passes (#83).

Sonar findings in the functions changed: nesting, nested conditionals, commented-out code, std::format,
references to const. Unit tests: test::pair for two vehicles running into each other, test_couplers,
test_horn, test_wheelslip, test_compressor, test_radio, test_gauge_positions.
2026-10-17 14:41:59 +02:00

81 lines
2.6 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
using test::definition;
using test::vehicle;
// the compressor waiting a while after getting its power before it starts (CompressorStartDelay,
// MaSzyna-EU07/maszyna#67): in a diesel it starts some time after the engine, rather than with it
namespace {
double const step{0.01};
// a compressor fed from the main circuit, which starts on its own, and an empty main reservoir for it to fill
vehicle compressor_vehicle(double const Delay) {
auto definition{definition::load("wagon")};
definition.set("Brake", "Vv", 1.0).set("Brake", "MinCP", 0.65).set("Brake", "MaxCP", 0.8);
definition.set("Brake", "CompressorSpeed", 0.01).set("Brake", "CompressorPower", "Main");
definition.set("Cntrl", "CompressorStart", "Automatic");
if (Delay > 0.0) {
definition.set("Brake", "CompressorStartDelay", Delay);
}
vehicle vehicle{definition};
vehicle->CompressedVolume = 0.0;
vehicle->LastSwitchingTime = 10.0; // nothing was switched lately
return vehicle;
}
// runs the compressor for Seconds, the main circuit as it is, the time since the last switching going on as in
// ComputeTotalForce()
void run_compressor(vehicle &Vehicle, double const Seconds) {
for (auto i{std::lround(Seconds / step)}; i > 0; --i) {
Vehicle->LastSwitchingTime += step;
Vehicle->CompressorCheck(step);
}
}
} // namespace
TEST_CASE("compressor: without a start delay the compressor starts with its power") {
auto vehicle{compressor_vehicle(0.0)};
run_compressor(vehicle, 1.0);
REQUIRE_FALSE(vehicle->CompressorFlag); // no power, no compressor
vehicle->Mains = true;
run_compressor(vehicle, step);
CHECK(vehicle->CompressorFlag);
}
TEST_CASE("compressor: the compressor starts the delay after getting its power") {
auto vehicle{compressor_vehicle(5.0)};
vehicle->Mains = true;
run_compressor(vehicle, 4.9);
CHECK_FALSE(vehicle->CompressorFlag);
CHECK(vehicle->Compressor == doctest::Approx(0.0));
run_compressor(vehicle, 0.2);
CHECK(vehicle->CompressorFlag);
run_compressor(vehicle, 10.0);
CHECK(vehicle->Compressor > 0.0); // and fills the reservoir
}
TEST_CASE("compressor: the delay starts over once the power is gone") {
auto vehicle{compressor_vehicle(5.0)};
vehicle->Mains = true;
run_compressor(vehicle, 10.0);
REQUIRE(vehicle->CompressorFlag);
vehicle->Mains = false; // the engine stopped
run_compressor(vehicle, 1.0);
CHECK_FALSE(vehicle->CompressorFlag);
vehicle->Mains = true; // and started again
run_compressor(vehicle, 4.9);
CHECK_FALSE(vehicle->CompressorFlag);
run_compressor(vehicle, 0.2);
CHECK(vehicle->CompressorFlag);
}