From 039f3c135aa7fef148ca26370da99d2b40bd9598 Mon Sep 17 00:00:00 2001 From: Arthur O'Dwyer Date: Sun, 17 Feb 2019 00:50:09 -0500 Subject: [PATCH] slot_map tests: Generalize BoundsCheckingTest. And add a Vector::clear() method so that this test passes even for type `slot_map_5`. --- SG14_test/slot_map_test.cpp | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/SG14_test/slot_map_test.cpp b/SG14_test/slot_map_test.cpp index ae0eda66..a8727c90 100644 --- a/SG14_test/slot_map_test.cpp +++ b/SG14_test/slot_map_test.cpp @@ -81,6 +81,10 @@ struct Vector { data_ = std::move(p); *(end() - 1) = std::move(t); } + void clear() { + size_ = 0; + data_ = nullptr; + } friend void swap(Vector& a, Vector& b) { Vector t = std::move(a); a = std::move(b); @@ -419,30 +423,32 @@ static void TypedefTests() #endif // __cplusplus >= 201703L } +template void BoundsCheckingTest() { - stdext::slot_map sm; + using T = typename SM::mapped_type; + SM sm; const auto& csm = sm; - sm.emplace(1); - stdext::slot_map::key_type k = sm.emplace(2); + sm.emplace(Monad::from_value(1)); + typename SM::key_type k = sm.emplace(Monad::from_value(2)); sm.clear(); - stdext::slot_map::iterator it = sm.find(k); + typename SM::iterator it = sm.find(k); assert(it == sm.end()); - stdext::slot_map::const_iterator cit = csm.find(k); + typename SM::const_iterator cit = csm.find(k); assert(cit == sm.end()); } void sg14_test::slot_map_test() { TypedefTests(); - BoundsCheckingTest(); // Test the most basic slot_map. using slot_map_1 = stdext::slot_map; BasicTests(42, 37); + BoundsCheckingTest(); FullContainerStressTest([]() { return 1; }); InsertEraseStressTest([i=3]() mutable { return ++i; }); EraseInLoopTest(); @@ -453,6 +459,7 @@ void sg14_test::slot_map_test() // Test slot_map with a custom key type (C++14 destructuring). using slot_map_2 = stdext::slot_map; BasicTests(425, 375); + BoundsCheckingTest(); FullContainerStressTest([]() { return 42; }); InsertEraseStressTest([i=5]() mutable { return ++i; }); EraseInLoopTest(); @@ -464,6 +471,7 @@ void sg14_test::slot_map_test() // Test slot_map with a custom key type (C++17 destructuring). using slot_map_3 = stdext::slot_map; BasicTests(42, 37); + BoundsCheckingTest(); FullContainerStressTest([]() { return 42; }); InsertEraseStressTest([i=3]() mutable { return ++i; }); EraseInLoopTest(); @@ -475,6 +483,7 @@ void sg14_test::slot_map_test() // Test slot_map with a custom (but standard and random-access) container type. using slot_map_4 = stdext::slot_map, std::deque>; BasicTests(415, 315); + BoundsCheckingTest(); FullContainerStressTest([]() { return 37; }); InsertEraseStressTest([i=7]() mutable { return ++i; }); EraseInLoopTest(); @@ -485,6 +494,7 @@ void sg14_test::slot_map_test() // Test slot_map with a custom (non-standard, random-access) container type. using slot_map_5 = stdext::slot_map, TestContainer::Vector>; BasicTests(415, 315); + BoundsCheckingTest(); FullContainerStressTest([]() { return 37; }); InsertEraseStressTest([i=7]() mutable { return ++i; }); EraseInLoopTest(); @@ -495,6 +505,7 @@ void sg14_test::slot_map_test() // Test slot_map with a custom (standard, bidirectional-access) container type. using slot_map_6 = stdext::slot_map, std::list>; BasicTests(415, 315); + BoundsCheckingTest(); FullContainerStressTest([]() { return 37; }); InsertEraseStressTest([i=7]() mutable { return ++i; }); EraseInLoopTest(); @@ -510,6 +521,7 @@ void sg14_test::slot_map_test() static_assert(! std::is_copy_constructible::value, ""); static_assert(! std::is_copy_assignable::value, ""); BasicTests(std::make_unique(1), std::make_unique(2)); + BoundsCheckingTest(); FullContainerStressTest([]() { return std::make_unique(1); }); InsertEraseStressTest([i=7]() mutable { return std::make_unique(++i); }); EraseInLoopTest();