Skip to content

Commit a46f9a8

Browse files
authored
test(bigtable): refactor CheckEqualUnordered (#10482)
1 parent afc873a commit a46f9a8

File tree

2 files changed

+17
-51
lines changed

2 files changed

+17
-51
lines changed

google/cloud/bigtable/testing/table_integration_test.cc

Lines changed: 15 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "google/cloud/testing_util/status_matchers.h"
2020
#include "absl/memory/memory.h"
2121
#include <google/protobuf/text_format.h>
22+
#include <gmock/gmock.h>
2223
#include <algorithm>
2324
#include <cctype>
2425

@@ -27,14 +28,24 @@ namespace cloud {
2728
namespace bigtable {
2829
namespace testing {
2930

31+
MATCHER(CellEqual, "") {
32+
auto const& rhs = std::get<0>(arg);
33+
auto const& lhs = std::get<1>(arg);
34+
return rhs.row_key() == lhs.row_key() &&
35+
rhs.family_name() == lhs.family_name() &&
36+
rhs.column_qualifier() == lhs.column_qualifier() &&
37+
rhs.timestamp() == lhs.timestamp() && rhs.value() == lhs.value() &&
38+
rhs.labels() == lhs.labels();
39+
}
40+
3041
bigtable_admin::BigtableTableAdminClient TableAdminClient() {
3142
return bigtable_admin::BigtableTableAdminClient(
3243
bigtable_admin::MakeBigtableTableAdminConnection());
3344
}
3445

3546
using ::google::cloud::internal::GetEnv;
36-
using ::testing::ContainerEq;
3747
using ::testing::IsEmpty;
48+
using ::testing::UnorderedPointwise;
3849

3950
std::string TableTestEnvironment::project_id_;
4051
std::string TableTestEnvironment::instance_id_;
@@ -248,10 +259,9 @@ std::vector<bigtable::Cell> TableIntegrationTest::GetCellsIgnoringTimestamp(
248259
}
249260

250261
void TableIntegrationTest::CheckEqualUnordered(
251-
std::vector<bigtable::Cell> expected, std::vector<bigtable::Cell> actual) {
252-
std::sort(expected.begin(), expected.end());
253-
std::sort(actual.begin(), actual.end());
254-
EXPECT_THAT(actual, ContainerEq(expected));
262+
std::vector<bigtable::Cell> const& expected,
263+
std::vector<bigtable::Cell> const& actual) {
264+
EXPECT_THAT(actual, UnorderedPointwise(CellEqual(), expected));
255265
}
256266

257267
std::string TableIntegrationTest::RandomTableId() {
@@ -272,49 +282,6 @@ std::string TableIntegrationTest::RandomBackupId() {
272282

273283
} // namespace testing
274284

275-
int CellCompare(bigtable::Cell const& lhs, bigtable::Cell const& rhs) {
276-
auto compare_row_key = internal::CompareRowKey(lhs.row_key(), rhs.row_key());
277-
if (compare_row_key != 0) {
278-
return compare_row_key;
279-
}
280-
auto compare_family_name = lhs.family_name().compare(rhs.family_name());
281-
if (compare_family_name != 0) {
282-
return compare_family_name;
283-
}
284-
auto compare_column_qualifier = internal::CompareColumnQualifiers(
285-
lhs.column_qualifier(), rhs.column_qualifier());
286-
if (compare_column_qualifier != 0) {
287-
return compare_column_qualifier;
288-
}
289-
if (lhs.timestamp() < rhs.timestamp()) {
290-
return -1;
291-
}
292-
if (lhs.timestamp() > rhs.timestamp()) {
293-
return 1;
294-
}
295-
auto compare_value = internal::CompareCellValues(lhs.value(), rhs.value());
296-
if (compare_value != 0) {
297-
return compare_value;
298-
}
299-
if (lhs.labels() < rhs.labels()) {
300-
return -1;
301-
}
302-
if (lhs.labels() == rhs.labels()) {
303-
return 0;
304-
}
305-
return 1;
306-
}
307-
308-
//@{
309-
/// @name Helpers for GTest.
310-
bool operator==(Cell const& lhs, Cell const& rhs) {
311-
return CellCompare(lhs, rhs) == 0;
312-
}
313-
314-
bool operator<(Cell const& lhs, Cell const& rhs) {
315-
return CellCompare(lhs, rhs) < 0;
316-
}
317-
318285
/**
319286
* This function is not used in this file, but it is used by GoogleTest; without
320287
* it, failing tests will output binary blobs instead of human-readable text.
@@ -331,7 +298,6 @@ void PrintTo(bigtable::Cell const& cell, std::ostream* os) {
331298
}
332299
*os << "}";
333300
}
334-
//@}
335301

336302
} // namespace bigtable
337303
} // namespace cloud

google/cloud/bigtable/testing/table_integration_test.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,8 +131,8 @@ class TableIntegrationTest
131131
* Compare two sets of cells.
132132
* Unordered because ReadRows does not guarantee a particular order.
133133
*/
134-
static void CheckEqualUnordered(std::vector<bigtable::Cell> expected,
135-
std::vector<bigtable::Cell> actual);
134+
static void CheckEqualUnordered(std::vector<bigtable::Cell> const& expected,
135+
std::vector<bigtable::Cell> const& actual);
136136

137137
/**
138138
* Generate a random table id.

0 commit comments

Comments
 (0)