Googletest: comparison of two arrays

Created on 9 Jul 2016  路  1Comment  路  Source: google/googletest

For some of my low lever work, array comparison is always inconvient. would it be possible to add to the package something like:

 template<typename T, size_t size>
    ::testing::AssertionResult ArraysMatch(const T (&expected)[size],
                                           const T (&actual)[size]){
        for (size_t i(0); i < size; ++i){
            if (expected[i] != actual[i]){
                return ::testing::AssertionFailure() << "array[" << i
                    << "] (" << actual[i] << ") != expected[" << i
                    << "] (" << expected[i] << ")";
            }
        }

        return ::testing::AssertionSuccess();
    }

I found it here: http://stackoverflow.com/questions/10060110/how-does-gtest-compare-the-values-in-two-arrays

Most helpful comment

include "gmock/gmock.h"

TEST(..., ...)
{
EXPECT_THAT(array, ElementsAre(1,2,3,4...));
}

>All comments

include "gmock/gmock.h"

TEST(..., ...)
{
EXPECT_THAT(array, ElementsAre(1,2,3,4...));
}

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ElectricRCAircraftGuy picture ElectricRCAircraftGuy  路  4Comments

tschijnmo picture tschijnmo  路  4Comments

markfrazzetto picture markfrazzetto  路  3Comments

maygamboa picture maygamboa  路  6Comments

pepe82sh picture pepe82sh  路  5Comments