17
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-10-18 13:49:19 +02:00
Files
maszyna/tests/unit/test_gauge_positions.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

47 lines
1.6 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle/gaugepositions.h"
#include <string>
// the sounds of the positions of a cab control (MaSzyna-EU07/maszyna#83): a brake lever moved smoothly (Num3/Num9)
// passes its positions instead of stopping at them, and sounds each one it reaches, as it does when put there
namespace {
// a brake lever with sounds at positions 0, 2 and 5; values in hundredths of a position
std::map<int, std::string> lever_sounds() {
return {{0, "release"}, {2, "running"}, {5, "service"}};
}
std::string reached(int const Previous, int const Desired) {
auto positions{lever_sounds()};
auto const position{gauge_positions::last_reached(positions, Previous, Desired)};
return position != positions.end() ? position->second : "";
}
} // namespace
TEST_CASE("gauge positions: a lever put at a position sounds it") {
CHECK(reached(100, 200) == "running");
CHECK(reached(600, 500) == "service");
}
TEST_CASE("gauge positions: a lever moved smoothly past a position sounds it (MaSzyna-EU07/maszyna#83)") {
CHECK(reached(190, 205) == "running"); // moving up
CHECK(reached(510, 495) == "service"); // moving down
}
TEST_CASE("gauge positions: of the positions passed in one go the last one reached sounds") {
CHECK(reached(50, 520) == "service"); // up past 2 and 5
CHECK(reached(520, 10) == "running"); // down past 5 and 2, short of 0
CHECK(reached(520, 0) == "release");
}
TEST_CASE("gauge positions: moving between the positions or off one sounds nothing") {
CHECK(reached(210, 290) == "");
CHECK(reached(200, 230) == ""); // leaving a position isn't reaching it
CHECK(reached(200, 170) == "");
}