From a5fff60a6165869cdd68d383867c6afa4134aca6 Mon Sep 17 00:00:00 2001 From: Tom Hicks Date: Sat, 15 Apr 2023 18:43:04 -0700 Subject: [PATCH] Adds vector compare helper to TinyTest. --- sbf-cpp/test.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/sbf-cpp/test.h b/sbf-cpp/test.h index 1af22b9..3c8b2ad 100644 --- a/sbf-cpp/test.h +++ b/sbf-cpp/test.h @@ -41,6 +41,25 @@ auto& operator<<(std::basic_ostream& os, std::vector v) { return os; } +template +auto& compare(std::basic_ostream& error_message, std::vector expected, std::vector actual) { + if (expected.size() != actual.size()) { + error_message << "size mismatch expected: " << expected.size() << ", actual: " << actual.size(); + return error_message; + } + + for (size_t index = 0; index < expected.size(); index++) { + if (expected[index] != actual[index]) { + error_message << "vectors differ at index " << index + << ", \"" << expected[index] << "\" != \"" << actual[index] + << "\", expected: " << expected + << ", actual: " << actual; + return error_message; + } + } + return error_message; +} + namespace Test { using std::tuple; using std::pair;