18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 07:07:05 +01:00
Files
maszyna/tests/unit/test_invariants.cpp
T
Hirek d0387753f8 refactor(physics): TMoverParameters becomes physics::Vehicle, the mover is gone
The physics of a vehicle loses the name it had from the Pascal of 2001. Done by
tools/rename/mover_to_physics.py, committed with it:

  physics/mover.h                  physics/vehicle.h
  TMoverParameters                 physics::Vehicle (in namespace physics)
  TDynamicObject::MoverParameters  physics
  mvOccupied, mvControlled         occupied, controlled (TTrain, TController)
  mvSecond, mvThird                secondUnit, thirdUnit
  mvPantographUnit                 pantographUnit
  mover, Mover, movers             physics, Physics, vehicles (locals, params)
  m_mover, othermover, currentMover, from_movers, renderMoverEventSounds
                                   m_physics, otherPhysics, currentPhysics,
                                   from_vehicles, renderPhysicsEventSounds

The code and the comments are renamed, the string literals are not: no text
the game shows, logs or looks up has changed (none had the names). The movers
of the editor, the tracks a slide moves, keep their name.

By hand: two member functions of TDynamicObject (gather_off_track_terrain,
begin_off_track) had a local mover aliasing their own MoverParameters, which
the rename made physics { *physics }; the alias is gone, they use physics->.
No other function has a renamed local meeting a renamed member (checked over
all the functions of the code before the rename).

For the branches made before it: run the script on the branch (python
tools/rename/mover_to_physics.py, from the root of the repository) before
merging it with this one, and the names don't conflict. It can be run again;
the second time it changes nothing.

The class is the same as it was; breaking it into its parts (braking,
electrics, controls, load) and making its data private are the next stages.

No change in behaviour: 1149/1149 tests, golden traces exact against staging
62f7a29b.
2026-11-28 23:56:46 +01:00

35 lines
1.2 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "golden.h"
#include "vehicle.h"
// the invariants every golden trace checks (invariants.h) catch a vehicle in a state the simulation must
// never reach, once each, naming the time and the last event
using test::definition;
using test::vehicle;
TEST_CASE("invariants: a vehicle in an impossible state, reported once with its time and the last event") {
vehicle eu07{definition::fiz("4e_v1/4e")};
test::trace trace{"invariants/self test", test::channels::brakes()};
trace.sample(0.0, eu07.physics());
CHECK(trace.violations().empty());
trace.mark("overfilled");
eu07->BrakePress = 50.0;
trace.sample(0.01, eu07.physics());
trace.sample(0.02, eu07.physics());
REQUIRE(trace.violations().size() == 1);
auto const &violation{trace.violations().front()};
CHECK(violation.find("brake cylinders") != std::string::npos);
CHECK(violation.find("at 0.010 s") != std::string::npos);
CHECK(violation.find("after \"overfilled\"") != std::string::npos);
CHECK(violation.find("BrakePress=50") != std::string::npos);
eu07->BrakePress = 0.0;
eu07->V = std::nan("");
trace.sample(0.03, eu07.physics());
CHECK(trace.violations().size() > 1);
CHECK(trace.violations()[1].find("every value a number") != std::string::npos);
}