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_queries.cpp
T
Hirek 2098614f8c refactor(physics): the couplings are Coupling and CouplingSet, not the bits of an int
What a coupling between two vehicles joins (the coupler, the brake hose, the
control cable, the high voltage...) was an int of bits, tested as
(flag & 36) == 36, (x & coupling::control) != 0, TestFlag(), SetFlag(x, -y),
compared with 0 and 3, with the same values twice (coupling:: and ctrain_).

- enum class Coupling (coupler, brakeHose, control, highVoltage, gangway,
  mainHose, heating, permanent, power24v, power110v, power3x400v), the values
  the scenery files and the definitions have always used; ctrain_* is gone
- CouplingSet, a set of them: HasAll(), HasAny(), Empty(), Set(), Clear()
  (as SetFlag() and ClearFlag() worked), Without(), |, &, ^, ==, and a test
  of any kind in a condition
- TCoupling's CouplingFlag, AllowedFlag, AutomaticCouplingFlag, PowerFlag and
  PowerCoupling, TCommand's couplings (was Coupling), the coupling parameters
  of the commands, Attach(), CompatibleCoupling(), Next(), Prev(),
  FirstFind(), is_connected(), the AI's iCoupler are CouplingSet
- the numbers are read into a set where they come in: the .fiz (BuffCoupl,
  negative AllowedFlag still meaning permanent), the scenery trainsets, the
  AI's Connect command, InvCtrCplFlag; and written as numbers where they go
  out: the scenery loader, the black box, the debug panels, DettachStatus()
- (CouplingFlag & 36) == 36 reads HasAll(Coupling::control | Coupling::mainHose)

No change in behaviour: 1144/1144 tests, golden traces exact against staging
62f7a29b.
2026-11-27 23:20:53 +01:00

62 lines
2.4 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
// characterisation of what the game's panels read of a vehicle besides the gauges recorded in the traces: the
// description of its damage on the driver's panel (driveruipanels.cpp)
using test::definition;
using test::vehicle;
TEST_CASE("queries: the damage of a vehicle as the driver's panel describes it") {
vehicle locomotive{definition::fiz("4e_v1/4e")};
vehicle wagon{definition::fiz("3wl_v2/3wl")};
// a powered locomotive and a wagon read some of the flags differently
locomotive->Power = 2000.0;
REQUIRE(wagon->Power < 0.1);
struct damage {
int flag;
char const *locomotive;
char const *wagon;
};
for (auto const &[flag, locomotivetext, wagontext] : {
damage{0, "OK", "OK"},
damage{dtrain_thinwheel, "Thin wheel", "Load shifted"},
damage{dtrain_wheelwear, "Wheel wear", "Wheel wear"},
damage{dtrain_bearing, "Bearing damaged", "Bearing damaged"},
damage{dtrain_coupling, "Coupler broken", "Coupler broken"},
damage{dtrain_loaddamage, "Ventilator damaged", "Load damaged"},
damage{dtrain_loaddestroyed, "Engine damaged", "LOAD DESTROYED"},
damage{dtrain_axle, "Axle broken", "Axle broken"},
damage{dtrain_out, "DERAILED", "DERAILED"},
// the last flag of the list wins
damage{dtrain_bearing | dtrain_axle, "Axle broken", "Axle broken"},
damage{255, "WRECKED", "WRECKED"},
}) {
CAPTURE(flag);
locomotive->DamageFlag = flag;
wagon->DamageFlag = flag;
CHECK(locomotive->EngineDescription(0) == locomotivetext);
CHECK(wagon->EngineDescription(0) == wagontext);
}
// flat wheels count as worn ones
wagon->DamageFlag = 0;
wagon->WheelFlat = 6.0;
CHECK(wagon->EngineDescription(0) == "Wheel wear");
// nothing else is described
CHECK(wagon->EngineDescription(1) == "Invalid qualifier");
}
TEST_CASE("queries: the ammeters of a vehicle without power show the current of the ones it controls") {
vehicle unpowered{definition::fiz("en57_v1/6ba_840")};
vehicle powered{definition::fiz("en57_v1/5bgb")};
unpowered->Attach(end::rear, end::front, &powered.mover(), Coupling::control, true, false);
powered->Power = 600.0;
powered->Itot = 321.7;
unpowered->Power = 0.0;
CHECK(unpowered->ShowCurrent(0) == doctest::Approx(321.0)); // whole amperes
powered->Power = 0.0;
CHECK(unpowered->ShowCurrent(0) == doctest::Approx(0.0));
}