aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/gencnt
diff options
context:
space:
mode:
authorJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
committerJon Bratseth <bratseth@yahoo-inc.com>2016-06-15 23:09:44 +0200
commit72231250ed81e10d66bfe70701e64fa5fe50f712 (patch)
tree2728bba1131a6f6e5bdf95afec7d7ff9358dac50 /vespalib/src/tests/gencnt
Publish
Diffstat (limited to 'vespalib/src/tests/gencnt')
-rw-r--r--vespalib/src/tests/gencnt/.gitignore4
-rw-r--r--vespalib/src/tests/gencnt/CMakeLists.txt8
-rw-r--r--vespalib/src/tests/gencnt/DESC2
-rw-r--r--vespalib/src/tests/gencnt/FILES1
-rw-r--r--vespalib/src/tests/gencnt/gencnt_test.cpp86
5 files changed, 101 insertions, 0 deletions
diff --git a/vespalib/src/tests/gencnt/.gitignore b/vespalib/src/tests/gencnt/.gitignore
new file mode 100644
index 00000000000..682aec97b1a
--- /dev/null
+++ b/vespalib/src/tests/gencnt/.gitignore
@@ -0,0 +1,4 @@
+.depend
+Makefile
+gencnt_test
+vespalib_gencnt_test_app
diff --git a/vespalib/src/tests/gencnt/CMakeLists.txt b/vespalib/src/tests/gencnt/CMakeLists.txt
new file mode 100644
index 00000000000..ddacebae09f
--- /dev/null
+++ b/vespalib/src/tests/gencnt/CMakeLists.txt
@@ -0,0 +1,8 @@
+# Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+vespa_add_executable(vespalib_gencnt_test_app
+ SOURCES
+ gencnt_test.cpp
+ DEPENDS
+ vespalib
+)
+vespa_add_test(NAME vespalib_gencnt_test_app COMMAND vespalib_gencnt_test_app)
diff --git a/vespalib/src/tests/gencnt/DESC b/vespalib/src/tests/gencnt/DESC
new file mode 100644
index 00000000000..6cdaa76b812
--- /dev/null
+++ b/vespalib/src/tests/gencnt/DESC
@@ -0,0 +1,2 @@
+Test GenCnt class. This class is used to hold a generation count and
+also to do some common calculations on it.
diff --git a/vespalib/src/tests/gencnt/FILES b/vespalib/src/tests/gencnt/FILES
new file mode 100644
index 00000000000..de6ec5596e1
--- /dev/null
+++ b/vespalib/src/tests/gencnt/FILES
@@ -0,0 +1 @@
+gencnt.cpp
diff --git a/vespalib/src/tests/gencnt/gencnt_test.cpp b/vespalib/src/tests/gencnt/gencnt_test.cpp
new file mode 100644
index 00000000000..af192dd1a78
--- /dev/null
+++ b/vespalib/src/tests/gencnt/gencnt_test.cpp
@@ -0,0 +1,86 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+#include <vespa/fastos/fastos.h>
+#include <vespa/log/log.h>
+LOG_SETUP("gencnt_test");
+#include <vespa/vespalib/testkit/testapp.h>
+#include <vespa/vespalib/util/gencnt.h>
+
+using vespalib::GenCnt;
+
+TEST_SETUP(Test);
+
+int
+Test::Main()
+{
+ TEST_INIT("gencnt_test");
+
+ GenCnt first;
+
+ GenCnt a;
+ GenCnt b;
+ GenCnt c;
+
+ a.setFromInt(5);
+ b.setFromInt(5);
+ c.setFromInt(5);
+ EXPECT_TRUE(a == b);
+ EXPECT_TRUE(!(a != b));
+ EXPECT_TRUE(b.inRangeInclusive(a, c));
+ EXPECT_TRUE(b.inRangeInclusive(c, a));
+
+ a.setFromInt(5);
+ b.setFromInt(6);
+ c.setFromInt(7);
+ EXPECT_TRUE(a != b);
+ EXPECT_TRUE(!(a == b));
+ EXPECT_TRUE(b.inRangeInclusive(a, c));
+ EXPECT_TRUE(!b.inRangeInclusive(c, a));
+ EXPECT_TRUE(!a.inRangeInclusive(b, c));
+ EXPECT_TRUE(a.inRangeInclusive(c, b));
+ EXPECT_TRUE(!first.inRangeInclusive(a, c));
+ EXPECT_TRUE(!first.inRangeInclusive(c, a));
+
+ a.setFromInt(10);
+ c = b = a;
+ b.add(10);
+ c.add(20);
+ EXPECT_TRUE(b.inRangeInclusive(a, c));
+ EXPECT_TRUE(!b.inRangeInclusive(c, a));
+ EXPECT_TRUE(!a.inRangeInclusive(b, c));
+ EXPECT_TRUE(a.inRangeInclusive(c, b));
+ EXPECT_TRUE(a.distance(b) == 10);
+ EXPECT_TRUE(a.distance(c) == 20);
+ EXPECT_TRUE(b.distance(c) == 10);
+ EXPECT_TRUE(!first.inRangeInclusive(a, c));
+ EXPECT_TRUE(!first.inRangeInclusive(c, a));
+
+ a.setFromInt((uint32_t)-5);
+ c = b = a;
+ b.add(10);
+ c.add(20);
+ EXPECT_TRUE(b.inRangeInclusive(a, c));
+ EXPECT_TRUE(!b.inRangeInclusive(c, a));
+ EXPECT_TRUE(!a.inRangeInclusive(b, c));
+ EXPECT_TRUE(a.inRangeInclusive(c, b));
+ EXPECT_TRUE(a.distance(b) == 10);
+ EXPECT_TRUE(a.distance(c) == 20);
+ EXPECT_TRUE(b.distance(c) == 10);
+ EXPECT_TRUE(!first.inRangeInclusive(a, c));
+ EXPECT_TRUE(!first.inRangeInclusive(c, a));
+
+ a.setFromInt((uint32_t)-15);
+ c = b = a;
+ b.add(10);
+ c.add(20);
+ EXPECT_TRUE(b.inRangeInclusive(a, c));
+ EXPECT_TRUE(!b.inRangeInclusive(c, a));
+ EXPECT_TRUE(!a.inRangeInclusive(b, c));
+ EXPECT_TRUE(a.inRangeInclusive(c, b));
+ EXPECT_TRUE(a.distance(b) == 10);
+ EXPECT_TRUE(a.distance(c) == 20);
+ EXPECT_TRUE(b.distance(c) == 10);
+ EXPECT_TRUE(!first.inRangeInclusive(a, c));
+ EXPECT_TRUE(!first.inRangeInclusive(c, a));
+
+ TEST_DONE();
+}