Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mapsme/omim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'base/base_tests/stl_add_test.cpp')
-rw-r--r--base/base_tests/stl_add_test.cpp107
1 files changed, 107 insertions, 0 deletions
diff --git a/base/base_tests/stl_add_test.cpp b/base/base_tests/stl_add_test.cpp
index 212dd3c1f7..094ed9f5af 100644
--- a/base/base_tests/stl_add_test.cpp
+++ b/base/base_tests/stl_add_test.cpp
@@ -85,3 +85,110 @@ UNIT_TEST(STLAdd_RemoveIfKeepValid)
TEST_EQUAL(v.size(), 4, ());
}
}
+
+namespace
+{
+ template <class T, size_t N1, size_t N2, size_t N3>
+ void CheckAccumulateIntervals(size_t & idTest,
+ pair<T, T> (&arr1)[N1],
+ pair<T, T> (&arr2)[N2],
+ pair<T, T> (&arr3)[N3])
+ {
+ vector<pair<T, T> > res;
+ AccumulateIntervals1With2(arr1, arr1 + N1, arr2, arr2 + N2, back_inserter(res));
+
+ ++idTest;
+ TEST_EQUAL(N3, res.size(), ("Test", idTest, res));
+ TEST(equal(res.begin(), res.end(), arr3), ("Test", idTest, res));
+ }
+}
+
+UNIT_TEST(STLAdd_AccumulateIntervals)
+{
+ typedef pair<int, int> T;
+ size_t idTest = 0;
+
+ // bound cases
+ {
+ vector<T> res;
+ T arr[] = { T(10, 20) };
+
+ res.clear();
+ AccumulateIntervals1With2(arr, arr + 1, arr, arr, back_inserter(res));
+ TEST_EQUAL(res.size(), 1, ());
+
+ res.clear();
+ AccumulateIntervals1With2(arr, arr, arr, arr + 1, back_inserter(res));
+ TEST_EQUAL(res.size(), 0, ());
+ }
+
+ // check splice overlapped
+ {
+ T arr1[] = { T(10, 20), T(30, 40) };
+ T arr2[] = { T(19, 31) };
+ T res[] = { T(10, 40) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+
+ // check skip not overlapped
+ {
+ T arr1[] = { T(10, 20), T(30, 40) };
+ T arr2[] = { T(0, 9), T(21, 29), T(41, 50) };
+ T res[2] = { T(10, 20), T(30, 40) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+ {
+ T arr1[] = { T(10, 20), T(30, 40) };
+ T arr2[] = { T(1, 2), T(3, 4), T(5, 6),
+ T(21, 22), T(23, 24), T(25, 26),
+ T(41, 42), T(43, 44), T(45, 46)
+ };
+ T res[] = { T(10, 20), T(30, 40) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+
+ // check equal bounds
+ {
+ T arr1[] = { T(20, 30) };
+ T arr2[] = { T(10, 20), T(30, 40) };
+ T res[] = { T(20, 30) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+ {
+ T arr1[] = { T(10, 20), T(30, 40) };
+ T arr2[] = { T(20, 30) };
+ T res[] = { T(10, 20), T(30, 40) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+
+ // check large overlap interval
+ {
+ T arr1[] = { T(10, 20), T(30, 40), T(50, 60) };
+ T arr2[] = { T(0, 100) };
+ T res[] = { T(0, 100) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+ {
+ T arr1[] = { T(0, 100) };
+ T arr2[] = { T(10, 20), T(30, 40), T(50, 60) };
+ T res[] = { T(0, 100) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+
+ // check splice overlapped
+ {
+ T arr1[] = { T(10, 20), T(30, 40) };
+ T arr2[] = { T(5, 15), T(35, 45) };
+ T res[] = { T(5, 20), T(30, 45) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+ {
+ T arr1[] = { T(10, 20), T(30, 40) };
+ T arr2[] = { T(1, 2), T(3, 4), T(5, 15),
+ T(17, 25), T(26, 27), T(28, 32),
+ T(38, 45), T(46, 50)
+ };
+ T res[] = { T(5, 25), T(28, 45) };
+ CheckAccumulateIntervals(idTest, arr1, arr2, res);
+ }
+}