From a44745e2fae25fa3ec5a2d439016943245bcbf15 Mon Sep 17 00:00:00 2001 From: Marijn van der Werf Date: Mon, 17 Oct 2016 23:12:54 +0200 Subject: [PATCH] Fix General/SegmentSupportHeightCalls --- test/testpaint/GeneralSupportHeightCall.cpp | 19 ++++++++------- test/testpaint/GeneralSupportHeightCall.hpp | 2 +- test/testpaint/SegmentSupportHeightCall.cpp | 23 +++++++++--------- test/testpaint/SegmentSupportHeightCall.hpp | 2 +- test/testpaint/TestTrack.cpp | 26 +++++++++------------ test/testpaint/main.cpp | 26 ++++++++++++--------- 6 files changed, 50 insertions(+), 48 deletions(-) diff --git a/test/testpaint/GeneralSupportHeightCall.cpp b/test/testpaint/GeneralSupportHeightCall.cpp index 774414371b..87a75ff973 100644 --- a/test/testpaint/GeneralSupportHeightCall.cpp +++ b/test/testpaint/GeneralSupportHeightCall.cpp @@ -27,7 +27,7 @@ bool GeneralSupportHeightCall::CallsMatch(SupportCall tileSupportCalls[4]) { return true; } -SupportCall *GeneralSupportHeightCall::FindMostCommonSupportCall(SupportCall calls[4]) { +bool GeneralSupportHeightCall::FindMostCommonSupportCall(SupportCall calls[4], SupportCall *out) { std::map map; for (int i = 0; i < 4; ++i) { @@ -39,30 +39,33 @@ SupportCall *GeneralSupportHeightCall::FindMostCommonSupportCall(SupportCall cal } if (map.size() == 1) { - return &calls[0]; + (*out) = calls[0]; + return true; } if (map.size() == 2) { for (auto &&item : map) { if (item.second == 3) { - return (SupportCall *)&item.first; + (*out) = item.first; + return true; } } - return nullptr; + return false; } if (map.size() == 3) { for (auto &&item : map) { - if (item.second == 2) { - return (SupportCall *)&item.first; + if (item.second == 2) { + (*out) = item.first; + return true; } } - return nullptr; + return false; } - return nullptr; + return false; } bool GeneralSupportHeightCall::AssertEquals(const SupportCall *lhs, const SupportCall *rhs) { diff --git a/test/testpaint/GeneralSupportHeightCall.hpp b/test/testpaint/GeneralSupportHeightCall.hpp index 9187ebaa62..919c43529e 100644 --- a/test/testpaint/GeneralSupportHeightCall.hpp +++ b/test/testpaint/GeneralSupportHeightCall.hpp @@ -45,7 +45,7 @@ struct SupportCall { namespace GeneralSupportHeightCall { bool CallsMatch(SupportCall tileSupportCalls[4]); - SupportCall *FindMostCommonSupportCall(SupportCall calls[4]); + bool FindMostCommonSupportCall(SupportCall calls[4], SupportCall *out); bool AssertEquals(const SupportCall *lhs, const SupportCall *rhs); }; diff --git a/test/testpaint/SegmentSupportHeightCall.cpp b/test/testpaint/SegmentSupportHeightCall.cpp index 05f3fbf906..082df5665c 100644 --- a/test/testpaint/SegmentSupportHeightCall.cpp +++ b/test/testpaint/SegmentSupportHeightCall.cpp @@ -114,40 +114,39 @@ bool SegmentSupportHeightCall::CallsEqual(std::vector lhs, s return true; } -std::vector* SegmentSupportHeightCall::FindMostCommonSupportCall(std::vector *calls) { +bool SegmentSupportHeightCall::FindMostCommonSupportCall(std::vector calls[4], std::vector *out) { std::map, int> map; for (int i = 0; i < 4; ++i) { - if (map.count(calls[i]) == 0) { - map[calls[i]] = 1; - } else { - map[calls[i]] += 1; - } + map[calls[i]] += 1; } if (map.size() == 1) { - return &calls[0]; + (*out) = calls[0]; + return true; } if (map.size() == 2) { for (auto &&item : map) { if (item.second == 3) { - return (std::vector *)&item.first; + (*out) = item.first; + return true; } } - return nullptr; + return false; } if (map.size() == 3) { for (auto &&item : map) { if (item.second == 2) { - return (std::vector *)&item.first; + (*out) = item.first; + return true; } } - return nullptr; + return false; } - return nullptr; + return false; } diff --git a/test/testpaint/SegmentSupportHeightCall.hpp b/test/testpaint/SegmentSupportHeightCall.hpp index c095a9d1ba..6b3c9728c2 100644 --- a/test/testpaint/SegmentSupportHeightCall.hpp +++ b/test/testpaint/SegmentSupportHeightCall.hpp @@ -48,5 +48,5 @@ public: static std::vector getSegmentCalls(support_height supports[9], uint8 rotation); static bool CallsMatch(std::vector tileSegmentSupportCalls[4]); static bool CallsEqual(std::vector lhs, std::vector rhs); - static std::vector * FindMostCommonSupportCall(std::vector calls[4]); + static bool FindMostCommonSupportCall(std::vector calls[4], std::vector * out); }; diff --git a/test/testpaint/TestTrack.cpp b/test/testpaint/TestTrack.cpp index 1f9e194c17..2534c0d79d 100644 --- a/test/testpaint/TestTrack.cpp +++ b/test/testpaint/TestTrack.cpp @@ -433,11 +433,8 @@ static uint8 TestTrackElementSegmentSupportHeight(uint8 rideType, uint8 trackTyp std::vector referenceCalls = tileSegmentSupportCalls[0]; if (!SegmentSupportHeightCall::CallsMatch(tileSegmentSupportCalls)) { - std::vector *found = SegmentSupportHeightCall::FindMostCommonSupportCall( - tileSegmentSupportCalls); - if (found != nullptr) { - referenceCalls = *found; - } else { + bool success = SegmentSupportHeightCall::FindMostCommonSupportCall(tileSegmentSupportCalls, &referenceCalls); + if (!success) { *error += String::Format("Original segment calls didn't match. %s\n", state.c_str()); for (int direction = 0; direction < 4; direction++) { *error += String::Format("# %d\n", direction); @@ -516,10 +513,10 @@ static uint8 TestTrackElementGeneralSupportHeight(uint8 rideType, uint8 trackTyp } } - SupportCall referenceGeneralSupportCall = tileGeneralSupportCalls[0]; + SupportCall referenceCall = tileGeneralSupportCalls[0]; if (!GeneralSupportHeightCall::CallsMatch(tileGeneralSupportCalls)) { - SupportCall *found = GeneralSupportHeightCall::FindMostCommonSupportCall(tileGeneralSupportCalls); - if (found == nullptr) { + bool success = GeneralSupportHeightCall::FindMostCommonSupportCall(tileGeneralSupportCalls, &referenceCall); + if (!success) { *error += String::Format("Original support calls didn't match. %s\n", state.c_str()); for (int i = 0; i < 4; ++i) { *error += String::Format("[%d, 0x%02X] ", tileGeneralSupportCalls[i].height, tileGeneralSupportCalls[i].slope); @@ -527,7 +524,6 @@ static uint8 TestTrackElementGeneralSupportHeight(uint8 rideType, uint8 trackTyp *error += "\n"; return TEST_FAILED; } - referenceGeneralSupportCall = *found; } for (int direction = 0; direction < 4; direction++) { @@ -540,11 +536,11 @@ static uint8 TestTrackElementGeneralSupportHeight(uint8 rideType, uint8 trackTyp } - if (referenceGeneralSupportCall.height != -1) { - if (gSupport.height != referenceGeneralSupportCall.height) { + if (referenceCall.height != -1) { + if (gSupport.height != referenceCall.height) { *error += String::Format( "General support heights didn't match. (expected height + %d, actual: height + %d) [direction:%d] %s\n", - referenceGeneralSupportCall.height - height, + referenceCall.height - height, gSupport.height - height, direction, state.c_str() @@ -552,11 +548,11 @@ static uint8 TestTrackElementGeneralSupportHeight(uint8 rideType, uint8 trackTyp return TEST_FAILED; } } - if (referenceGeneralSupportCall.slope != -1) { - if (gSupport.slope != referenceGeneralSupportCall.slope) { + if (referenceCall.slope != -1) { + if (gSupport.slope != referenceCall.slope) { *error += String::Format( "General support slopes didn't match. (expected 0x%02X, actual: 0x%02X) [direction:%d] %s\n", - referenceGeneralSupportCall.slope, + referenceCall.slope, gSupport.slope, direction, state.c_str() diff --git a/test/testpaint/main.cpp b/test/testpaint/main.cpp index 985e680c31..ad1363762b 100644 --- a/test/testpaint/main.cpp +++ b/test/testpaint/main.cpp @@ -366,27 +366,31 @@ static void TestGeneralSupportHeightCall() { SupportCall callC = {48, 0x20}; SupportCall callD = {48, 0x1F}; - SupportCall *result; + SupportCall out = {0,0}; + bool success; SupportCall groupA[4] = {callA, callA, callA, callA}; - result = GeneralSupportHeightCall::FindMostCommonSupportCall(groupA); - assert(GeneralSupportHeightCall::AssertEquals(result, &callA)); + success = GeneralSupportHeightCall::FindMostCommonSupportCall(groupA, &out); + assert(success); + assert(out == callA); SupportCall groupB[4] = {callB, callA, callA, callA}; - result = GeneralSupportHeightCall::FindMostCommonSupportCall(groupB); - assert(GeneralSupportHeightCall::AssertEquals(result, &callA)); + success = GeneralSupportHeightCall::FindMostCommonSupportCall(groupB, &out); + assert(success); + assert(out == callA); SupportCall groupC[4] = {callB, callA, callB, callA}; - result = GeneralSupportHeightCall::FindMostCommonSupportCall(groupC); - assert(GeneralSupportHeightCall::AssertEquals(result, nullptr)); + success = GeneralSupportHeightCall::FindMostCommonSupportCall(groupC, &out); + assert(!success); SupportCall groupD[4] = {callB, callC, callB, callA}; - result = GeneralSupportHeightCall::FindMostCommonSupportCall(groupD); - assert(GeneralSupportHeightCall::AssertEquals(result, &callB)); + success = GeneralSupportHeightCall::FindMostCommonSupportCall(groupD, &out); + assert(success); + assert(out == callB); SupportCall groupE[4] = {callD, callC, callB, callA}; - result = GeneralSupportHeightCall::FindMostCommonSupportCall(groupE); - assert(GeneralSupportHeightCall::AssertEquals(result, nullptr)); + success = GeneralSupportHeightCall::FindMostCommonSupportCall(groupE, &out); + assert(!success); } int main(int argc, char *argv[]) {