From 59c20bcb2b72998abbd354a6d63072b87f10fc86 Mon Sep 17 00:00:00 2001 From: Mikhail Gorbushin Date: Tue, 30 Apr 2019 15:43:46 +0300 Subject: [PATCH] Stage 2. Add tests for NonIntersectingIntervals. --- base/base_tests/CMakeLists.txt | 3 +- .../non_intersecting_intervals_tests.cpp | 79 +++++++++++++++++++ 2 files changed, 81 insertions(+), 1 deletion(-) create mode 100644 base/base_tests/non_intersecting_intervals_tests.cpp diff --git a/base/base_tests/CMakeLists.txt b/base/base_tests/CMakeLists.txt index a26725b164..56b8b6e191 100644 --- a/base/base_tests/CMakeLists.txt +++ b/base/base_tests/CMakeLists.txt @@ -25,6 +25,7 @@ set( mem_trie_test.cpp move_to_front_tests.cpp newtype_test.cpp + non_intersecting_intervals_tests.cpp observer_list_test.cpp range_iterator_test.cpp ref_counted_tests.cpp @@ -37,9 +38,9 @@ set( string_utils_test.cpp suffix_array_tests.cpp sunrise_sunset_test.cpp - thread_pool_tests.cpp thread_pool_computational_tests.cpp thread_pool_delayed_tests.cpp + thread_pool_tests.cpp threaded_list_test.cpp threads_test.cpp timegm_test.cpp diff --git a/base/base_tests/non_intersecting_intervals_tests.cpp b/base/base_tests/non_intersecting_intervals_tests.cpp new file mode 100644 index 0000000000..b9fea1b557 --- /dev/null +++ b/base/base_tests/non_intersecting_intervals_tests.cpp @@ -0,0 +1,79 @@ +#include "testing/testing.hpp" + +#include "base/non_intersecting_intervals.hpp" + +namespace +{ +using namespace base; + +UNIT_TEST(NonIntersectingIntervals_1) +{ + NonIntersectingIntervals intervals; + + TEST(intervals.AddInterval(1, 10), ()); + TEST(intervals.AddInterval(11, 15), ()); + // overlap with [1, 10] + TEST(!intervals.AddInterval(1, 20), ()); + + // overlap with [11, 15] + TEST(!intervals.AddInterval(13, 20), ()); + + // overlap with [1, 10] and [11, 15] + TEST(!intervals.AddInterval(0, 100), ()); + + TEST(intervals.AddInterval(100, 150), ()); + + // overlap with [100, 150] + TEST(!intervals.AddInterval(90, 200), ()); +} + +UNIT_TEST(NonIntersectingIntervals_2) +{ + NonIntersectingIntervals intervals; + + TEST(intervals.AddInterval(1, 10), ()); + // overlap with [1, 10] + TEST(!intervals.AddInterval(2, 9), ()); +} + +UNIT_TEST(NonIntersectingIntervals_3) +{ + NonIntersectingIntervals intervals; + + TEST(intervals.AddInterval(1, 10), ()); + // overlap with [1, 10] + TEST(!intervals.AddInterval(0, 20), ()); +} + +UNIT_TEST(NonIntersectingIntervals_4) +{ + NonIntersectingIntervals intervals; + + TEST(intervals.AddInterval(1, 10), ()); + // overlap with [1, 10] + TEST(!intervals.AddInterval(10, 20), ()); + TEST(!intervals.AddInterval(0, 1), ()); +} + +UNIT_TEST(NonIntersectingIntervals_5) +{ + NonIntersectingIntervals intervals; + + TEST(intervals.AddInterval(0, 1), ()); + + // Overlap with [0, 1]. + TEST(!intervals.AddInterval(1, 2), ()); + + TEST(intervals.AddInterval(2, 3), ()); + TEST(intervals.AddInterval(4, 5), ()); + + // Overlap with [0, 1] and [2, 3]. + TEST(!intervals.AddInterval(1, 3), ()); + + // Overlap with [2, 3]. + TEST(!intervals.AddInterval(2, 2), ()); + + // Overlap with [2, 3] and [4, 5]. + TEST(!intervals.AddInterval(2, 5), ()); +} +} // namespace