From f39a4a4a4e48acb1afd96101796d72ea060cf6f5 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 20 Mar 2019 14:05:30 +0100 Subject: Cleanup: More C++ like nature for word split test While it looks more longer, but also contains more comments about what's going on. Surely, this function almost never breaks and investing time into maintaining its tests is not that important, but we should have a good, clean, understandable tests so they act as a nice example of how they are to be written. Especially important to show correct language usage, without old school macros magic. Doing this at a lunch breaks, so will be series of some updates in the area. --- tests/gtests/testing/testing.h | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) (limited to 'tests/gtests/testing') diff --git a/tests/gtests/testing/testing.h b/tests/gtests/testing/testing.h index d5a7b076970..9efdbe22557 100644 --- a/tests/gtests/testing/testing.h +++ b/tests/gtests/testing/testing.h @@ -1,6 +1,8 @@ #ifndef __BLENDER_TESTING_H__ #define __BLENDER_TESTING_H__ +#include + #include "glog/logging.h" #include "gflags/gflags.h" #include "gtest/gtest.h" @@ -99,17 +101,28 @@ double CosinusBetweenMatrices(const TMat &a, const TMat &b) { #endif template -inline void EXPECT_EQ_ARRAY(const T *expected, T *actual, const size_t N) { +inline void EXPECT_EQ_VECTOR(const std::vector& expected, const std::vector& actual) { + EXPECT_EQ(expected.size(), actual.size()); + if (expected.size() == actual.size()) { + for(size_t i = 0; i < expected.size(); ++i) { + EXPECT_EQ(expected[i], actual[i]) << "Element mismatch at index " << i; + } + } +} + +template +inline void EXPECT_EQ_ARRAY(const T *expected, const T *actual, const size_t N) { for(size_t i = 0; i < N; ++i) { - EXPECT_EQ(expected[i], actual[i]); + EXPECT_EQ(expected[i], actual[i]) << "Element mismatch at index " << i; } } template -inline void EXPECT_EQ_ARRAY_ND(const T *expected, T *actual, const size_t N, const size_t D) { +inline void EXPECT_EQ_ARRAY_ND(const T *expected, const T *actual, const size_t N, const size_t D) { for(size_t i = 0; i < N; ++i) { for(size_t j = 0; j < D; ++j) { - EXPECT_EQ(expected[i][j], actual[i][j]); + EXPECT_EQ(expected[i][j], actual[i][j]) + << "Element mismatch at index " << i << ", component index " << j; } } } -- cgit v1.2.3