OpenRCT2/test/tests/AssertHelpers.hpp

31 lines
1.1 KiB
C++
Raw Permalink Normal View History

/*****************************************************************************
* Copyright (c) 2014-2024 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
2017-02-25 17:07:08 +01:00
#pragma once
2018-06-22 22:29:03 +02:00
#include <gtest/gtest.h>
2017-02-25 17:07:08 +01:00
#include <initializer_list>
#include <vector>
2021-07-24 23:41:50 +02:00
template<typename T, typename TExpected> static void AssertVector(const std::vector<T>& actual, TExpected expected)
2017-02-25 17:07:08 +01:00
{
2018-06-22 22:29:03 +02:00
ASSERT_EQ(actual.size(), expected.size()) << "Expected vector of size " << expected.size() << ", but was " << actual.size();
2017-02-25 17:07:08 +01:00
size_t i = 0;
for (auto item : expected)
{
2018-06-22 22:29:03 +02:00
EXPECT_EQ(actual[i], item) << "Element at index " << i << " did not match";
2017-02-25 17:07:08 +01:00
i++;
}
}
2021-07-24 23:41:50 +02:00
template<typename T> static void AssertVector(const std::vector<T>& actual, std::initializer_list<T> expected)
2017-02-25 17:07:08 +01:00
{
AssertVector<T, std::initializer_list<T>>(actual, expected);
}