18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-12-01 18:47:06 +01:00
Files
maszyna/tests/unit/test_wipers.cpp
T
jerrrrycho 4bd7565a81 fix: read the WiperList wiper mask as a number, not a character
byteSum is a uint8_t, and cParser reads an unsigned char as one character
of the token: "5" became 53, and "12" became '1' (49), wiper 0 alone
instead of wipers 2 and 3. The single digits in the current data kept the
right low bits by chance. Read it as an int, clamped to the byte's range.
2026-11-28 06:53:59 +01:00

51 lines
1.6 KiB
C++

#include "stdafx.h"
#include "doctest.h"
#include "vehicle.h"
using test::definition;
using test::vehicle;
// the first number of a WiperList row is the mask of the wipers working in that position of the wiper switch,
// bit n for the wiper n. it's a number: read as a character "5" was 53 and "12" was '1', the wiper 0 alone
namespace {
definition wiper_list(nlohmann::ordered_json const &Rows) {
return definition::load("cab_vehicle")
.set("WiperList", "rows", Rows)
.set("WiperList", "Size", static_cast<int>(Rows.size()))
.set("WiperList", "Angle", 58);
}
} // namespace
TEST_CASE("wipers: the mask of the wipers of a WiperList row is read as a number") {
vehicle cab{wiper_list(nlohmann::ordered_json::array({
{"0", "0.7", "0.0", "0.5"},
{"5", "0.7", "7.0", "0.5"},
{"12", "0.6", "0.7", "0.0"},
{"15", "0.5", "0.5", "0.25"},
}))};
REQUIRE(cab->WiperListSize == 4);
CHECK(cab->WiperList[0].byteSum == 0);
CHECK(cab->WiperList[1].byteSum == 5);
CHECK(cab->WiperList[2].byteSum == 12);
CHECK(cab->WiperList[3].byteSum == 15);
// and the numbers after it still land in their own fields
CHECK(cab->WiperList[1].interval == doctest::Approx(7.0));
CHECK(cab->WiperList[2].WiperSpeed == doctest::Approx(0.6));
CHECK(cab->WiperList[3].outBackDelay == doctest::Approx(0.25));
}
TEST_CASE("wipers: a mask out of the range of a byte is clamped to it") {
vehicle cab{wiper_list(nlohmann::ordered_json::array({
{"-1", "0.7", "0.0", "0.5"},
{"300", "0.7", "0.0", "0.5"},
}))};
CHECK(cab->WiperList[0].byteSum == 0);
CHECK(cab->WiperList[1].byteSum == 255);
}