Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(488)

Unified Diff: blimp/net/helium/vector_clock_unittest.cc

Issue 2372903002: Helium: Adding vector clock (Closed)
Patch Set: allowing merge with conflicted vectors Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« blimp/net/helium/vector_clock.cc ('K') | « blimp/net/helium/vector_clock.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: blimp/net/helium/vector_clock_unittest.cc
diff --git a/blimp/net/helium/vector_clock_unittest.cc b/blimp/net/helium/vector_clock_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..f67e86b5559e64079ce71bcd5cc0eed35ca05835
--- /dev/null
+++ b/blimp/net/helium/vector_clock_unittest.cc
@@ -0,0 +1,153 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "blimp/net/helium/vector_clock.h"
+
+#include "base/macros.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace blimp {
+namespace {
+
+class VectorClockComparisonTest
+ : public ::testing::TestWithParam<
+ std::tuple<VectorClock, VectorClock, VectorClock::Comparison>> {
+ public:
+ VectorClockComparisonTest() {}
+ ~VectorClockComparisonTest() override {}
+};
+
+TEST_P(VectorClockComparisonTest, CompareTo) {
+ auto param = GetParam();
+ VectorClock v1 = std::get<0>(param);
+ VectorClock v2 = std::get<1>(param);
+ VectorClock::Comparison expected = std::get<2>(param);
+ EXPECT_EQ(expected, v1.CompareTo(v2));
+}
+
+INSTANTIATE_TEST_CASE_P(
Kevin M 2016/09/27 17:31:10 Wow, this is pretty cool. I was unaware of this st
+ LessThan,
+ VectorClockComparisonTest,
+ ::testing::Values(std::make_tuple(VectorClock(1, 2),
+ VectorClock(1, 3),
+ VectorClock::Comparison::LessThan),
+ std::make_tuple(VectorClock(1, 2),
+ VectorClock(2, 2),
+ VectorClock::Comparison::LessThan)));
+
+INSTANTIATE_TEST_CASE_P(
+ GreaterThan,
+ VectorClockComparisonTest,
+ ::testing::Values(std::make_tuple(VectorClock(1, 3),
+ VectorClock(1, 2),
+ VectorClock::Comparison::GreaterThan),
+ std::make_tuple(VectorClock(2, 2),
+ VectorClock(1, 2),
+ VectorClock::Comparison::GreaterThan)));
+
+INSTANTIATE_TEST_CASE_P(
+ Conflicts,
+ VectorClockComparisonTest,
+ ::testing::Values(std::make_tuple(VectorClock(1, 2),
+ VectorClock(0, 1),
+ VectorClock::Comparison::Conflicts),
+ std::make_tuple(VectorClock(1, 2),
+ VectorClock(0, 3),
+ VectorClock::Comparison::Conflicts),
+ std::make_tuple(VectorClock(1, 2),
+ VectorClock(2, 3),
+ VectorClock::Comparison::Conflicts)));
+
+INSTANTIATE_TEST_CASE_P(
+ EqualTo,
+ VectorClockComparisonTest,
+ ::testing::Values(std::make_tuple(VectorClock(1, 1),
+ VectorClock(1, 1),
+ VectorClock::Comparison::EqualTo),
+ std::make_tuple(VectorClock(2, 3),
+ VectorClock(2, 3),
+ VectorClock::Comparison::EqualTo),
+ std::make_tuple(VectorClock(3, 2),
+ VectorClock(3, 2),
+ VectorClock::Comparison::EqualTo)));
+
+class VectorClockTest : public testing::Test {
+ public:
+ VectorClockTest() {}
+ ~VectorClockTest() override {}
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(VectorClockTest);
+};
+
+TEST_F(VectorClockTest, IncrementLocal1) {
+ VectorClock v(0, 0);
+ v.IncrementLocal();
+ EXPECT_EQ(1, v.local_revision());
+ EXPECT_EQ(0, v.remote_revision());
+}
+
+TEST_F(VectorClockTest, IncrementLocal2) {
+ VectorClock v(4, 5);
+ v.IncrementLocal();
+ EXPECT_EQ(5, v.local_revision());
+ EXPECT_EQ(5, v.remote_revision());
+}
+
+TEST_F(VectorClockTest, MergeWith1) {
+ VectorClock v1(1, 2);
Kevin M 2016/09/27 17:31:10 We could cut down on the number of test cases by m
+ VectorClock v2(1, 4);
+
+ VectorClock v3 = v1.MergeWith(v2);
+ EXPECT_EQ(1, v3.local_revision());
+ EXPECT_EQ(4, v3.remote_revision());
+}
+
+TEST_F(VectorClockTest, MergeWith2) {
+ VectorClock v1(1, 4);
+ VectorClock v2(1, 2);
+
+ VectorClock v3 = v1.MergeWith(v2);
+ EXPECT_EQ(1, v3.local_revision());
+ EXPECT_EQ(4, v3.remote_revision());
+}
+
+TEST_F(VectorClockTest, MergeWith3) {
+ VectorClock v1(1, 4);
+ VectorClock v2(2, 4);
+
+ VectorClock v3 = v1.MergeWith(v2);
+ EXPECT_EQ(2, v3.local_revision());
+ EXPECT_EQ(4, v3.remote_revision());
+}
+
+TEST_F(VectorClockTest, MergeWith4) {
+ VectorClock v1(2, 4);
+ VectorClock v2(1, 4);
+
+ VectorClock v3 = v1.MergeWith(v2);
+ EXPECT_EQ(2, v3.local_revision());
+ EXPECT_EQ(4, v3.remote_revision());
+}
+
+TEST_F(VectorClockTest, MergeWith5) {
+ VectorClock v1(1, 2);
+ VectorClock v2(3, 4);
+
+ VectorClock v3 = v1.MergeWith(v2);
+ EXPECT_EQ(3, v3.local_revision());
+ EXPECT_EQ(4, v3.remote_revision());
+}
+
+TEST_F(VectorClockTest, MergeWith6) {
+ VectorClock v1(3, 4);
+ VectorClock v2(1, 2);
+
+ VectorClock v3 = v1.MergeWith(v2);
+ EXPECT_EQ(3, v3.local_revision());
+ EXPECT_EQ(4, v3.remote_revision());
+}
+
+} // namespace
+} // namespace blimp
« blimp/net/helium/vector_clock.cc ('K') | « blimp/net/helium/vector_clock.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698