#include "stdafx.h" #include "doctest.h" #include "physics/vehicletypes.h" // the ends and the sides of a vehicle: the numbers the formats give them, the other one, the arrays indexed by them, // the end of a cab and of a pantograph of the model TEST_CASE("vehicle ends and sides keep the numbers of the formats") { CHECK(NumberOf(VehicleEnd::front) == 0); CHECK(NumberOf(VehicleEnd::rear) == 1); CHECK(NumberOf(VehicleSide::right) == 0); CHECK(NumberOf(VehicleSide::left) == 1); // a number goes through as it is, also the -1 and the 2 some fields hold for "none" for (auto const number : {-1, 0, 1, 2}) { CAPTURE(number); CHECK(NumberOf(EndOf(number)) == number); CHECK(NumberOf(SideOf(number)) == number); } } TEST_CASE("vehicle ends and sides: the other one") { CHECK(Opposite(VehicleEnd::front) == VehicleEnd::rear); CHECK(Opposite(VehicleEnd::rear) == VehicleEnd::front); CHECK(Opposite(VehicleSide::right) == VehicleSide::left); CHECK(Opposite(VehicleSide::left) == VehicleSide::right); CHECK(VehicleEnds[0] == VehicleEnd::front); CHECK(VehicleEnds[1] == VehicleEnd::rear); CHECK(VehicleSides[0] == VehicleSide::right); CHECK(VehicleSides[1] == VehicleSide::left); } TEST_CASE("an array of the ends is indexed by the end and by its number alike") { ByEnd values{10, 20}; CHECK(values[VehicleEnd::front] == 10); CHECK(values[VehicleEnd::rear] == 20); CHECK(values[0] == 10); CHECK(values[1] == 20); values[VehicleEnd::rear] = 30; CHECK(values[1] == 30); BySide doors{}; doors[VehicleSide::left] = true; CHECK_FALSE(doors[VehicleSide::right]); CHECK(doors[1]); } TEST_CASE("the cab of a vehicle is at its front for cab 1, at its rear for cab -1") { // the OFF position of the headlights dimmer puts out the headlights at the end of the active cab (A at the front, // B at the rear); with the numbers of the ends taken for the numbers of the cabs, cab 1 put out B and cab -1 nothing CHECK(CabEnd(1) == VehicleEnd::front); CHECK(CabEnd(-1) == VehicleEnd::rear); CHECK_FALSE(CabEnd(0).has_value()); } TEST_CASE("the pantographs of a model count for the front and the rear in turn") { // each pantograph has the voltage, the switch and the energy of its own end: the first one the front's, the second // one the rear's. the energy meter took the voltage of the other one, the count of the pantographs touching the // wire the switch of the front for both CHECK(PantographEnd(0) == VehicleEnd::front); CHECK(PantographEnd(1) == VehicleEnd::rear); CHECK(PantographEnd(2) == VehicleEnd::front); CHECK(PantographEnd(3) == VehicleEnd::rear); }