From a594d6b6752ae9c3904dc56c8d0ac0256dff3fbd Mon Sep 17 00:00:00 2001 From: Tomas Pecka <peckato1@fit.cvut.cz> Date: Sun, 24 Feb 2019 09:53:16 +0100 Subject: [PATCH] Unit tests: CPPUNIT -> Catch2: std --- .../test-src/extensions/AlgorithmTest.cpp | 220 +++---- alib2std/test-src/extensions/AlgorithmTest.h | 27 - alib2std/test-src/extensions/ApplyTest.cpp | 38 +- alib2std/test-src/extensions/ApplyTest.h | 19 - alib2std/test-src/extensions/CompareTest.cpp | 63 +- alib2std/test-src/extensions/CompareTest.h | 19 - alib2std/test-src/extensions/ForeachTest.cpp | 62 +- alib2std/test-src/extensions/ForeachTest.h | 21 - .../test-src/extensions/FunctionalTest.cpp | 23 +- alib2std/test-src/extensions/FunctionalTest.h | 19 - .../test-src/extensions/HexavigesimalTest.cpp | 72 +-- .../test-src/extensions/HexavigesimalTest.h | 19 - alib2std/test-src/extensions/IstreamTest.cpp | 31 +- alib2std/test-src/extensions/IstreamTest.h | 19 - alib2std/test-src/extensions/IteratorTest.cpp | 100 ++- alib2std/test-src/extensions/IteratorTest.h | 23 - alib2std/test-src/extensions/MemoryTest.cpp | 36 +- alib2std/test-src/extensions/MemoryTest.h | 18 - alib2std/test-src/extensions/OstreamTest.cpp | 54 +- alib2std/test-src/extensions/OstreamTest.h | 19 - .../test-src/extensions/ParamPassTest.cpp | 225 ++++--- alib2std/test-src/extensions/ParamPassTest.h | 18 - alib2std/test-src/extensions/RandomTest.cpp | 29 +- alib2std/test-src/extensions/RandomTest.h | 19 - alib2std/test-src/extensions/RangeTest.cpp | 88 ++- alib2std/test-src/extensions/RangeTest.h | 24 - .../test-src/extensions/SharedPtrTest.cpp | 190 ++++-- alib2std/test-src/extensions/SharedPtrTest.h | 89 --- alib2std/test-src/extensions/TypeInfoTest.cpp | 105 ++-- alib2std/test-src/extensions/TypeInfoTest.h | 32 - .../test-src/extensions/TypeTraitsTest.cpp | 63 +- alib2std/test-src/extensions/TypeTraitsTest.h | 22 - alib2std/test-src/extensions/UtilityTest.cpp | 31 +- alib2std/test-src/extensions/UtilityTest.h | 19 - .../extensions/container/ArrayTest.cpp | 25 +- .../test-src/extensions/container/ArrayTest.h | 19 - .../extensions/container/ForwardTreeTest.cpp | 227 +++---- .../extensions/container/ForwardTreeTest.h | 38 -- .../extensions/container/LinearSetTest.cpp | 162 ++--- .../extensions/container/LinearSetTest.h | 53 -- .../test-src/extensions/container/MapTest.cpp | 70 ++- .../test-src/extensions/container/MapTest.h | 53 -- .../extensions/container/PtrArrayTest.cpp | 106 +++- .../extensions/container/PtrArrayTest.h | 68 --- .../extensions/container/PtrTupleTest.cpp | 30 +- .../extensions/container/PtrTupleTest.h | 19 - .../extensions/container/PtrVectorTest.cpp | 221 ++++--- .../extensions/container/PtrVectorTest.h | 108 ---- .../test-src/extensions/container/SetTest.cpp | 143 +++-- .../test-src/extensions/container/SetTest.h | 49 -- .../extensions/container/StringTest.cpp | 110 ++-- .../extensions/container/StringTest.h | 27 - .../extensions/container/TreeBaseTest.cpp | 139 ++++- .../extensions/container/TreeBaseTest.h | 113 ---- .../extensions/container/TreeTest.cpp | 260 ++++---- .../test-src/extensions/container/TreeTest.h | 38 -- .../extensions/container/TrieTest.cpp | 119 ++-- .../test-src/extensions/container/TrieTest.h | 38 -- .../extensions/container/TupleTest.cpp | 27 +- .../test-src/extensions/container/TupleTest.h | 19 - .../extensions/container/VariantTest.cpp | 357 ++++++----- .../extensions/container/VariantTest.h | 103 ---- .../extensions/container/VectorTest.cpp | 576 +++++++++--------- .../extensions/container/VectorTest.h | 68 --- .../managed/ManagedLinearSetTest.cpp | 69 +-- .../container/managed/ManagedLinearSetTest.h | 18 - .../container/managed/ManagedValueTest.cpp | 25 +- .../container/managed/ManagedValueTest.h | 18 - .../test-src/extensions/heaps/HeapsTest.cpp | 185 +++--- .../test-src/extensions/heaps/HeapsTest.h | 19 - alib2std/test-src/main.cpp | 166 +---- 71 files changed, 2284 insertions(+), 3457 deletions(-) delete mode 100644 alib2std/test-src/extensions/AlgorithmTest.h delete mode 100644 alib2std/test-src/extensions/ApplyTest.h delete mode 100644 alib2std/test-src/extensions/CompareTest.h delete mode 100644 alib2std/test-src/extensions/ForeachTest.h delete mode 100644 alib2std/test-src/extensions/FunctionalTest.h delete mode 100644 alib2std/test-src/extensions/HexavigesimalTest.h delete mode 100644 alib2std/test-src/extensions/IstreamTest.h delete mode 100644 alib2std/test-src/extensions/IteratorTest.h delete mode 100644 alib2std/test-src/extensions/MemoryTest.h delete mode 100644 alib2std/test-src/extensions/OstreamTest.h delete mode 100644 alib2std/test-src/extensions/ParamPassTest.h delete mode 100644 alib2std/test-src/extensions/RandomTest.h delete mode 100644 alib2std/test-src/extensions/RangeTest.h delete mode 100644 alib2std/test-src/extensions/SharedPtrTest.h delete mode 100644 alib2std/test-src/extensions/TypeInfoTest.h delete mode 100644 alib2std/test-src/extensions/TypeTraitsTest.h delete mode 100644 alib2std/test-src/extensions/UtilityTest.h delete mode 100644 alib2std/test-src/extensions/container/ArrayTest.h delete mode 100644 alib2std/test-src/extensions/container/ForwardTreeTest.h delete mode 100644 alib2std/test-src/extensions/container/LinearSetTest.h delete mode 100644 alib2std/test-src/extensions/container/MapTest.h delete mode 100644 alib2std/test-src/extensions/container/PtrArrayTest.h delete mode 100644 alib2std/test-src/extensions/container/PtrTupleTest.h delete mode 100644 alib2std/test-src/extensions/container/PtrVectorTest.h delete mode 100644 alib2std/test-src/extensions/container/SetTest.h delete mode 100644 alib2std/test-src/extensions/container/StringTest.h delete mode 100644 alib2std/test-src/extensions/container/TreeBaseTest.h delete mode 100644 alib2std/test-src/extensions/container/TreeTest.h delete mode 100644 alib2std/test-src/extensions/container/TrieTest.h delete mode 100644 alib2std/test-src/extensions/container/TupleTest.h delete mode 100644 alib2std/test-src/extensions/container/VariantTest.h delete mode 100644 alib2std/test-src/extensions/container/VectorTest.h delete mode 100644 alib2std/test-src/extensions/container/managed/ManagedLinearSetTest.h delete mode 100644 alib2std/test-src/extensions/container/managed/ManagedValueTest.h delete mode 100644 alib2std/test-src/extensions/heaps/HeapsTest.h diff --git a/alib2std/test-src/extensions/AlgorithmTest.cpp b/alib2std/test-src/extensions/AlgorithmTest.cpp index 0979b622dd..843df3b74d 100644 --- a/alib2std/test-src/extensions/AlgorithmTest.cpp +++ b/alib2std/test-src/extensions/AlgorithmTest.cpp @@ -1,173 +1,145 @@ -#include "AlgorithmTest.h" +#include <catch2/catch.hpp> + #include <alib/algorithm> #include <alib/set> #include <alib/vector> #include <alib/list> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( AlgorithmTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( AlgorithmTest ); - -void AlgorithmTest::setUp() { -} +TEST_CASE ( "Algorithm Test", "[unit][std][bits]" ) { + SECTION ( "Exclude" ) { + { + int array1[] = {1, 2, 3}; + int array2[] = {2, 3, 4}; -void AlgorithmTest::tearDown() { -} + CHECK(ext::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == false); + } -void AlgorithmTest::testExclude() { - { - int array1[] = {1, 2, 3}; - int array2[] = {2, 3, 4}; + { + int array1[] = {1, 3, 5}; + int array2[] = {2, 4, 6, 8}; - std::cout << sizeof(array1) / sizeof(int); + CHECK(ext::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == true); + CHECK(ext::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == true); + } - CPPUNIT_ASSERT(ext::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == false); - } + { + int array1[] = {1, 3, 5, 8}; + int array2[] = {2, 4, 6, 8}; - { - int array1[] = {1, 3, 5}; - int array2[] = {2, 4, 6, 8}; + CHECK(ext::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == false); + CHECK(ext::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == false); + } - CPPUNIT_ASSERT(ext::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == true); - CPPUNIT_ASSERT(ext::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == true); - } + { + int array1[] = {0}; + int array2[] = {2, 4, 6, 8}; - { - int array1[] = {1, 3, 5, 8}; - int array2[] = {2, 4, 6, 8}; + CHECK(ext::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == true); + CHECK(ext::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == true); - CPPUNIT_ASSERT(ext::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == false); - CPPUNIT_ASSERT(ext::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == false); + CHECK(ext::excludes(array1, array1, array2, array2) == true); + CHECK(ext::excludes(array2, array2, array1, array1) == true); + } } - { - int array1[] = {0}; - int array2[] = {2, 4, 6, 8}; + SECTION ( "Transform" ) { + ext::set<int> in = {1, 2, 3, 4}; + ext::set<long> ref = {2, 3, 4, 5}; - CPPUNIT_ASSERT(ext::excludes(array1, array1 + sizeof(array1) / sizeof(int), array2, array2 + sizeof(array2) / sizeof(int)) == true); - CPPUNIT_ASSERT(ext::excludes(array2, array2 + sizeof(array2) / sizeof(int), array1, array1 + sizeof(array1) / sizeof(int)) == true); + /* std::function<long(const int&)> lamb = [](const int& elem) { return (long) elem + 1; }; + ext::set<long> out = ext::transform<long>(in, lamb); //*/ - CPPUNIT_ASSERT(ext::excludes(array1, array1, array2, array2) == true); - CPPUNIT_ASSERT(ext::excludes(array2, array2, array1, array1) == true); - } -} + ext::set<long> out = ext::transform<long>(in, [](const int& elem) { return (long) elem + 1; }); -void AlgorithmTest::testTransform() { - ext::set<int> in = {1, 2, 3, 4}; - ext::set<long> ref = {2, 3, 4, 5}; + CHECK(ref == out); + } -/* std::function<long(const int&)> lamb = [](const int& elem) { return (long) elem + 1; }; - ext::set<long> out = ext::transform<long>(in, lamb); //*/ + SECTION ( "FindRange" ) { + { + std::string str = "abc<dee<fd<<>>>th>::rrr"; - ext::set<long> out = ext::transform<long>(in, [](const int& elem) { return (long) elem + 1; }); + std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); - CPPUNIT_ASSERT(ref == out); -} + CHECK ( range.first - str.begin ( ) == 3 ); + CHECK ( range.second - str.begin ( ) == 18 ); -void AlgorithmTest::testFindRange ( ) { - { - std::string str = "abc<dee<fd<<>>>th>::rrr"; + str.erase ( range.first, range.second ); - std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); + CHECK ( str == "abc::rrr" ); + } + { + std::string str = "aaa::abc<dee<fd<<>>>th>"; - std::cerr << range.first - str.begin ( ) << std::endl; - std::cerr << range.second - str.begin ( ) << std::endl; + std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); - CPPUNIT_ASSERT ( range.first - str.begin ( ) == 3 ); - CPPUNIT_ASSERT ( range.second - str.begin ( ) == 18 ); + CHECK ( range.first - str.begin ( ) == 8 ); + CHECK ( range.second - str.begin ( ) == 23 ); - str.erase ( range.first, range.second ); - std::cerr << str << std::endl; + str.erase ( range.first, range.second ); - CPPUNIT_ASSERT ( str == "abc::rrr" ); - } - { - std::string str = "aaa::abc<dee<fd<<>>>th>"; + CHECK ( str == "aaa::abc" ); + } + { + std::string str = "<dee<fd<<>>>th>aaa"; - std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); + std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); - std::cerr << range.first - str.begin ( ) << std::endl; - std::cerr << range.second - str.begin ( ) << std::endl; + CHECK ( range.first - str.begin ( ) == 0 ); + CHECK ( range.second - str.begin ( ) == 15 ); - CPPUNIT_ASSERT ( range.first - str.begin ( ) == 8 ); - CPPUNIT_ASSERT ( range.second - str.begin ( ) == 23 ); + str.erase ( range.first, range.second ); - str.erase ( range.first, range.second ); - std::cerr << str << std::endl; + CHECK ( str == "aaa" ); + } + { + std::string str = "<dee<fd<<>>>th>"; - CPPUNIT_ASSERT ( str == "aaa::abc" ); - } - { - std::string str = "<dee<fd<<>>>th>aaa"; + std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); - std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); + CHECK ( range.first - str.begin ( ) == 0 ); + CHECK ( range.second - str.begin ( ) == 15 ); - std::cerr << range.first - str.begin ( ) << std::endl; - std::cerr << range.second - str.begin ( ) << std::endl; + str.erase ( range.first, range.second ); + CHECK ( str == "" ); + } - CPPUNIT_ASSERT ( range.first - str.begin ( ) == 0 ); - CPPUNIT_ASSERT ( range.second - str.begin ( ) == 15 ); + { + std::string str = "<dee<fd<<>>>th"; - str.erase ( range.first, range.second ); - std::cerr << str << std::endl; + std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); - CPPUNIT_ASSERT ( str == "aaa" ); + CHECK ( range.first - str.begin ( ) == 14 ); + CHECK ( range.second - str.begin ( ) == 14 ); + } } - { - std::string str = "<dee<fd<<>>>th>"; - std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); + SECTION ( "Symmetric Difference" ) { + ext::set < int > a { 1, 3, 5, 6, 7, 8, 9 }; + ext::set < int > b { 1, 2, 3, 4, 5, 7, 8 }; - std::cerr << range.first - str.begin ( ) << std::endl; - std::cerr << range.second - str.begin ( ) << std::endl; + ext::vector < int > a_b { 6, 9 }; + ext::vector < int > b_a { 2, 4 }; - CPPUNIT_ASSERT ( range.first - str.begin ( ) == 0 ); - CPPUNIT_ASSERT ( range.second - str.begin ( ) == 15 ); + ext::vector < int > a_b2; + ext::vector < int > b_a2; - str.erase ( range.first, range.second ); - std::cerr << str << std::endl; + ext::set_symmetric_difference ( a.begin ( ), a.end ( ), b.begin ( ), b.end ( ), std::back_inserter ( a_b2 ), std::back_inserter ( b_a2 ) ); - CPPUNIT_ASSERT ( str == "" ); + CHECK ( a_b == a_b2 ); + CHECK ( b_a == b_a2 ); } - { - std::string str = "<dee<fd<<>>>th"; + SECTION ( "Range Contains Iterator" ) { + std::list < int > test = { 1, 2, 3, 4, 5, 6 }; + std::list < int > other = { 1, 2, 3, 4, 5, 6, 7 }; + std::list < char > other2 = { 'a', 'b', 'c' }; - std::pair < std::string::iterator, std::string::iterator > range = ext::find_range ( str.begin ( ), str.end ( ), '<', '>' ); + std::list < int >::iterator iter = test.begin ( ); + iter++; + iter++; - std::cerr << range.first - str.begin ( ) << std::endl; - std::cerr << range.second - str.begin ( ) << std::endl; - - CPPUNIT_ASSERT ( range.first - str.begin ( ) == 14 ); - CPPUNIT_ASSERT ( range.second - str.begin ( ) == 14 ); + CHECK ( ext::range_contains_iterator ( test.begin ( ), test.end ( ), iter ) ); + CHECK ( ! ext::range_contains_iterator ( other.begin ( ), other.end ( ), iter ) ); + CHECK ( ! ext::range_contains_iterator ( other2.begin ( ), other2.end ( ), iter ) ); } } - -void AlgorithmTest::testSymmetricDifference ( ) { - ext::set < int > a { 1, 3, 5, 6, 7, 8, 9 }; - ext::set < int > b { 1, 2, 3, 4, 5, 7, 8 }; - - ext::vector < int > a_b { 6, 9 }; - ext::vector < int > b_a { 2, 4 }; - - ext::vector < int > a_b2; - ext::vector < int > b_a2; - - ext::set_symmetric_difference ( a.begin ( ), a.end ( ), b.begin ( ), b.end ( ), std::back_inserter ( a_b2 ), std::back_inserter ( b_a2 ) ); - - CPPUNIT_ASSERT ( a_b == a_b2 ); - CPPUNIT_ASSERT ( b_a == b_a2 ); -} - -void AlgorithmTest::testRangeContainsIterator ( ) { - std::list < int > test = { 1, 2, 3, 4, 5, 6 }; - std::list < int > other = { 1, 2, 3, 4, 5, 6, 7 }; - std::list < char > other2 = { 'a', 'b', 'c' }; - - std::list < int >::iterator iter = test.begin ( ); - iter++; - iter++; - - CPPUNIT_ASSERT ( ext::range_contains_iterator ( test.begin ( ), test.end ( ), iter ) ); - CPPUNIT_ASSERT ( ! ext::range_contains_iterator ( other.begin ( ), other.end ( ), iter ) ); - CPPUNIT_ASSERT ( ! ext::range_contains_iterator ( other2.begin ( ), other2.end ( ), iter ) ); -} diff --git a/alib2std/test-src/extensions/AlgorithmTest.h b/alib2std/test-src/extensions/AlgorithmTest.h deleted file mode 100644 index b9e589f788..0000000000 --- a/alib2std/test-src/extensions/AlgorithmTest.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef ALGORITHM_TEST_H_ -#define ALGORITHM_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class AlgorithmTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( AlgorithmTest ); - CPPUNIT_TEST( testExclude ); - CPPUNIT_TEST( testTransform ); - CPPUNIT_TEST( testFindRange ); - CPPUNIT_TEST( testSymmetricDifference ); - CPPUNIT_TEST( testRangeContainsIterator ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testExclude(); - void testTransform(); - void testFindRange(); - void testSymmetricDifference ( ); - void testRangeContainsIterator ( ); -}; - -#endif // ALGORITHM_TEST_H_ diff --git a/alib2std/test-src/extensions/ApplyTest.cpp b/alib2std/test-src/extensions/ApplyTest.cpp index 9c4a1b8a67..0d866b13fd 100644 --- a/alib2std/test-src/extensions/ApplyTest.cpp +++ b/alib2std/test-src/extensions/ApplyTest.cpp @@ -1,28 +1,28 @@ -#include "ApplyTest.h" -#include <alib/tuple> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ApplyTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( ApplyTest ); +#include <catch2/catch.hpp> -void ApplyTest::setUp ( ) { -} +#include <alib/tuple> -void ApplyTest::tearDown ( ) { +namespace { + class Foo { + public: + Foo ( int i ) : m_I ( i ) { } + int m_I; + }; } -class Foo { -public: -}; - -int tupleTestApply1 ( Foo, Foo ) { - return 1; +static int tupleTestApply1 ( Foo a, Foo b ) { + return a.m_I * b.m_I; } -int tupleTestApply2 ( int, int ) { - return 2; +static int tupleTestApply2 ( int a, int b ) { + return a + b; } -void ApplyTest::testApply ( ) { - std::tuple < int, int > t ( 1, 2 ); - CPPUNIT_ASSERT ( std::apply ( tupleTestApply2, t ) == 2 ); +TEST_CASE ( "Apply Test", "[unit][std][bits]" ) { + SECTION ( "Apply" ) { + std::tuple < Foo, Foo > t1 ( 1, 2 ); + std::tuple < int, int > t2 ( 1, 2 ); + CHECK ( std::apply ( tupleTestApply1, t1 ) == 2 ); + CHECK ( std::apply ( tupleTestApply2, t2 ) == 3 ); + } } diff --git a/alib2std/test-src/extensions/ApplyTest.h b/alib2std/test-src/extensions/ApplyTest.h deleted file mode 100644 index fc3ffb8f42..0000000000 --- a/alib2std/test-src/extensions/ApplyTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef _APPLY_TEST_H_ -#define _APPLY_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class ApplyTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE ( ApplyTest ); - CPPUNIT_TEST ( testApply ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - void setUp ( ); - void tearDown ( ); - - void testApply ( ); -}; - -#endif // _APPLY_TEST_H_ diff --git a/alib2std/test-src/extensions/CompareTest.cpp b/alib2std/test-src/extensions/CompareTest.cpp index 1d8cd9e859..0c0c425192 100644 --- a/alib2std/test-src/extensions/CompareTest.cpp +++ b/alib2std/test-src/extensions/CompareTest.cpp @@ -1,53 +1,46 @@ -#include "CompareTest.h" +#include <catch2/catch.hpp> + #include <alib/set> #include <alib/vector> #include <alib/pair> #include <alib/map> #include <alib/tuple> +TEST_CASE ( "Compare Test", "[unit][std][bits]" ) { + SECTION ( "Compare" ) { + ext::vector<int> vector1 {1, 2, 3}; + ext::vector<int> vector2 {2, 3, 4}; -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( CompareTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( CompareTest ); - -void CompareTest::setUp() { -} - -void CompareTest::tearDown() { -} - -void CompareTest::testCompare() { - ext::vector<int> vector1 {1, 2, 3}; - ext::vector<int> vector2 {2, 3, 4}; - - ext::compare<ext::vector<int>> comp1; - CPPUNIT_ASSERT(comp1(vector1, vector2) < 0); + ext::compare<ext::vector<int>> comp1; + CHECK(comp1(vector1, vector2) < 0); - ext::set<ext::vector<int>> set1 {vector1}; - ext::set<ext::vector<int>> set2 {vector2}; + ext::set<ext::vector<int>> set1 {vector1}; + ext::set<ext::vector<int>> set2 {vector2}; - ext::compare<ext::set<ext::vector<int>>> comp2; - CPPUNIT_ASSERT(comp2(set1, set2) < 0); + ext::compare<ext::set<ext::vector<int>>> comp2; + CHECK(comp2(set1, set2) < 0); - ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>> pair1 {set1, set2}; - ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>> pair2 {set2, set1}; + ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>> pair1 {set1, set2}; + ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>> pair2 {set2, set1}; - ext::compare<ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>>> comp3; - CPPUNIT_ASSERT(comp3(pair1, pair2) < 0); + ext::compare<ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>>> comp3; + CHECK(comp3(pair1, pair2) < 0); - int two = 2; - int three = 3; - int four = 4; + int two = 2; + int three = 3; + int four = 4; - ext::map<int, const int*> map1 = { {1, &two}, {2, &three} }; - ext::map<int, const int*> map2 = { {2, &three}, {3, &four} }; + ext::map<int, const int*> map1 = { {1, &two}, {2, &three} }; + ext::map<int, const int*> map2 = { {2, &three}, {3, &four} }; - ext::compare<ext::map<int, const int*>> comp4; - CPPUNIT_ASSERT(comp4(map1, map2) < 0); + ext::compare<ext::map<int, const int*>> comp4; + CHECK(comp4(map1, map2) < 0); - auto first = ext::tie(vector1, set1, pair1, map1); - auto second = ext::tie(vector2, set2, pair2, map2); + auto first = ext::tie(vector1, set1, pair1, map1); + auto second = ext::tie(vector2, set2, pair2, map2); - ext::compare<decltype ( first ) > comp5; - CPPUNIT_ASSERT(comp5(first, second) < 0); + ext::compare<decltype ( first ) > comp5; + CHECK(comp5(first, second) < 0); + } } diff --git a/alib2std/test-src/extensions/CompareTest.h b/alib2std/test-src/extensions/CompareTest.h deleted file mode 100644 index b56c879e93..0000000000 --- a/alib2std/test-src/extensions/CompareTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef COMPARE_TEST_H_ -#define COMPARE_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class CompareTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( CompareTest ); - CPPUNIT_TEST( testCompare ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testCompare(); -}; - -#endif // COMPARE_TEST_H_ diff --git a/alib2std/test-src/extensions/ForeachTest.cpp b/alib2std/test-src/extensions/ForeachTest.cpp index 7c2ead3012..c5ab74729b 100644 --- a/alib2std/test-src/extensions/ForeachTest.cpp +++ b/alib2std/test-src/extensions/ForeachTest.cpp @@ -1,41 +1,35 @@ -#include "ForeachTest.h" +#include <catch2/catch.hpp> + #include <alib/list> #include <alib/vector> #include <alib/foreach> #include <alib/set> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ForeachTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( ForeachTest ); - -void ForeachTest::setUp() { -} - -void ForeachTest::tearDown() { -} - -void ForeachTest::testForeach() { - ext::vector<int> vector1 {1, 2, 3}; - ext::list<int> list1 {2, 3, 4}; - - int i = 1; - for(const ext::tuple<const int&, const int&>& elements : ext::make_tuple_foreach(vector1, list1)) { - CPPUNIT_ASSERT(std::get<0>(elements) == i); - CPPUNIT_ASSERT(std::get<1>(elements) == i + 1); - i++; - } -} - -void ForeachTest::testForeach2() { - ext::vector<int> vector1 {1, 2, 3}; - ext::list<int> list1 {2, 3, 4}; - ext::set<int> set1 {3, 4, 5}; - - int i = 1; - for(const ext::tuple<const int&, const int&, const int&>& elements : ext::make_tuple_foreach(vector1, list1, set1)) { - CPPUNIT_ASSERT(std::get<0>(elements) == i); - CPPUNIT_ASSERT(std::get<1>(elements) == i + 1); - CPPUNIT_ASSERT(std::get<2>(elements) == i + 2); - i++; +TEST_CASE ( "Foreach Test", "[unit][std][bits]" ) { + SECTION ( "Foreach" ) { + { + ext::vector<int> vector1 {1, 2, 3}; + ext::list<int> list1 {2, 3, 4}; + + int i = 1; + for(const ext::tuple<const int&, const int&>& elements : ext::make_tuple_foreach(vector1, list1)) { + CHECK(std::get<0>(elements) == i); + CHECK(std::get<1>(elements) == i + 1); + i++; + } + } + { + ext::vector<int> vector1 {1, 2, 3}; + ext::list<int> list1 {2, 3, 4}; + ext::set<int> set1 {3, 4, 5}; + + int i = 1; + for(const ext::tuple<const int&, const int&, const int&>& elements : ext::make_tuple_foreach(vector1, list1, set1)) { + CHECK(std::get<0>(elements) == i); + CHECK(std::get<1>(elements) == i + 1); + CHECK(std::get<2>(elements) == i + 2); + i++; + } + } } } - diff --git a/alib2std/test-src/extensions/ForeachTest.h b/alib2std/test-src/extensions/ForeachTest.h deleted file mode 100644 index 36f0659413..0000000000 --- a/alib2std/test-src/extensions/ForeachTest.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef FOREACH_TEST_H_ -#define FOREACH_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class ForeachTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( ForeachTest ); - CPPUNIT_TEST( testForeach ); - CPPUNIT_TEST( testForeach2 ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testForeach(); - void testForeach2(); -}; - -#endif // FOREACH_TEST_H_ diff --git a/alib2std/test-src/extensions/FunctionalTest.cpp b/alib2std/test-src/extensions/FunctionalTest.cpp index abcdd76ed3..3336fb68d9 100644 --- a/alib2std/test-src/extensions/FunctionalTest.cpp +++ b/alib2std/test-src/extensions/FunctionalTest.cpp @@ -1,18 +1,13 @@ -#include "FunctionalTest.h" -#include <alib/functional> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( FunctionalTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( FunctionalTest ); +#include <catch2/extensions/HelperMacros.h> -void FunctionalTest::setUp() { -} +#include <alib/functional> -void FunctionalTest::tearDown() { -} +TEST_CASE ( "Functional Test", "[unit][std][bits]" ) { + SECTION ( "Less" ) { + ext::less < > test; + CHECK ( test ( 1, 2 ) == true ); + CHECK ( test ( 1, 2. ) == true ); -void FunctionalTest::testLess() { - ext::less < > test; - CPPUNIT_ASSERT ( test ( 1, 2 ) == true ); - CPPUNIT_ASSERT ( test ( 1, 2. ) == true ); - CPPUNIT_EXCLUSIVE_OR( test ( std::string ( "aa" ), 1 ), test ( 1, std::string ( "aa" ) ) ); + CHECK_EXCLUSIVE_OR( (test ( std::string ( "aa" ), 1 )), (test ( 1, std::string ( "aa" ) ) ) ); + } } diff --git a/alib2std/test-src/extensions/FunctionalTest.h b/alib2std/test-src/extensions/FunctionalTest.h deleted file mode 100644 index 8f859a7e49..0000000000 --- a/alib2std/test-src/extensions/FunctionalTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef FUNCTIONAL_TEST_H_ -#define FUNCTIONAL_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class FunctionalTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( FunctionalTest ); - CPPUNIT_TEST( testLess ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testLess(); -}; - -#endif // FUNCTIONAL_TEST_H_ diff --git a/alib2std/test-src/extensions/HexavigesimalTest.cpp b/alib2std/test-src/extensions/HexavigesimalTest.cpp index 3296cbe25e..3bb69c00d6 100644 --- a/alib2std/test-src/extensions/HexavigesimalTest.cpp +++ b/alib2std/test-src/extensions/HexavigesimalTest.cpp @@ -1,45 +1,39 @@ -#include "HexavigesimalTest.h" -#include <alib/hexavigesimal> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HexavigesimalTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( HexavigesimalTest ); - -void HexavigesimalTest::setUp() { -} +#include <catch2/catch.hpp> -void HexavigesimalTest::tearDown() { -} +#include <alib/hexavigesimal> -void HexavigesimalTest::test1() { - CPPUNIT_ASSERT_EQUAL(std::string("A") , ext::toBase26(0)); - CPPUNIT_ASSERT_EQUAL(std::string("B") , ext::toBase26(1)); - CPPUNIT_ASSERT_EQUAL(std::string("Z") , ext::toBase26(25)); - CPPUNIT_ASSERT_EQUAL(std::string("BA") , ext::toBase26(26)); - CPPUNIT_ASSERT_EQUAL(std::string("BB") , ext::toBase26(27)); - CPPUNIT_ASSERT_EQUAL(std::string("ZZ") , ext::toBase26(675)); - CPPUNIT_ASSERT_EQUAL(std::string("BAA"), ext::toBase26(676)); +TEST_CASE ( "Hexavigesimal", "[unit][std][bits]" ) { + SECTION ( "Hexavigesimal" ) { + CHECK(std::string("A") == ext::toBase26(0)); + CHECK(std::string("B") == ext::toBase26(1)); + CHECK(std::string("Z") == ext::toBase26(25)); + CHECK(std::string("BA") == ext::toBase26(26)); + CHECK(std::string("BB") == ext::toBase26(27)); + CHECK(std::string("ZZ") == ext::toBase26(675)); + CHECK(std::string("BAA") == ext::toBase26(676)); - CPPUNIT_ASSERT_EQUAL(0u , ext::fromBase26("A")); - CPPUNIT_ASSERT_EQUAL(1u , ext::fromBase26("B")); - CPPUNIT_ASSERT_EQUAL(25u , ext::fromBase26("Z")); - CPPUNIT_ASSERT_EQUAL(26u , ext::fromBase26("BA")); - CPPUNIT_ASSERT_EQUAL(27u , ext::fromBase26("BB")); - CPPUNIT_ASSERT_EQUAL(675u, ext::fromBase26("ZZ")); - CPPUNIT_ASSERT_EQUAL(676u, ext::fromBase26("BAA")); + CHECK(0u == ext::fromBase26("A")); + CHECK(1u == ext::fromBase26("B")); + CHECK(25u == ext::fromBase26("Z")); + CHECK(26u == ext::fromBase26("BA")); + CHECK(27u == ext::fromBase26("BB")); + CHECK(675u == ext::fromBase26("ZZ")); + CHECK(676u == ext::fromBase26("BAA")); - CPPUNIT_ASSERT_EQUAL(std::string("") , ext::bijectiveToBase26(0)); - CPPUNIT_ASSERT_EQUAL(std::string("A") , ext::bijectiveToBase26(1)); - CPPUNIT_ASSERT_EQUAL(std::string("Z") , ext::bijectiveToBase26(26)); - CPPUNIT_ASSERT_EQUAL(std::string("AA") , ext::bijectiveToBase26(27)); - CPPUNIT_ASSERT_EQUAL(std::string("AB") , ext::bijectiveToBase26(28)); - CPPUNIT_ASSERT_EQUAL(std::string("ZZ") , ext::bijectiveToBase26(702)); - CPPUNIT_ASSERT_EQUAL(std::string("AAA"), ext::bijectiveToBase26(703)); + CHECK(std::string("") == ext::bijectiveToBase26(0)); + CHECK(std::string("A") == ext::bijectiveToBase26(1)); + CHECK(std::string("Z") == ext::bijectiveToBase26(26)); + CHECK(std::string("AA") == ext::bijectiveToBase26(27)); + CHECK(std::string("AB") == ext::bijectiveToBase26(28)); + CHECK(std::string("ZZ") == ext::bijectiveToBase26(702)); + CHECK(std::string("AAA") == ext::bijectiveToBase26(703)); - CPPUNIT_ASSERT_EQUAL(0u , ext::bijectiveFromBase26("")); - CPPUNIT_ASSERT_EQUAL(1u , ext::bijectiveFromBase26("A")); - CPPUNIT_ASSERT_EQUAL(26u , ext::bijectiveFromBase26("Z")); - CPPUNIT_ASSERT_EQUAL(27u , ext::bijectiveFromBase26("AA")); - CPPUNIT_ASSERT_EQUAL(28u , ext::bijectiveFromBase26("AB")); - CPPUNIT_ASSERT_EQUAL(702u, ext::bijectiveFromBase26("ZZ")); - CPPUNIT_ASSERT_EQUAL(703u, ext::bijectiveFromBase26("AAA")); + CHECK(0u == ext::bijectiveFromBase26("")); + CHECK(1u == ext::bijectiveFromBase26("A")); + CHECK(26u == ext::bijectiveFromBase26("Z")); + CHECK(27u == ext::bijectiveFromBase26("AA")); + CHECK(28u == ext::bijectiveFromBase26("AB")); + CHECK(702u == ext::bijectiveFromBase26("ZZ")); + CHECK(703u == ext::bijectiveFromBase26("AAA")); + } } diff --git a/alib2std/test-src/extensions/HexavigesimalTest.h b/alib2std/test-src/extensions/HexavigesimalTest.h deleted file mode 100644 index a201d2e9fd..0000000000 --- a/alib2std/test-src/extensions/HexavigesimalTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef HEXAVIGESIMAL_TEST_H_ -#define HEXAVIGESIMAL_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class HexavigesimalTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( HexavigesimalTest ); - CPPUNIT_TEST( test1 ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void test1(); -}; - -#endif // HEXAVIGESIMAL_TEST_H_ diff --git a/alib2std/test-src/extensions/IstreamTest.cpp b/alib2std/test-src/extensions/IstreamTest.cpp index 9c289c281f..d53e182df7 100644 --- a/alib2std/test-src/extensions/IstreamTest.cpp +++ b/alib2std/test-src/extensions/IstreamTest.cpp @@ -1,4 +1,5 @@ -#include "IstreamTest.h" +#include <catch2/catch.hpp> + #include <alib/set> #include <alib/vector> #include <alib/pair> @@ -6,27 +7,19 @@ #include <alib/istream> #include <alib/string> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( IstreamTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( IstreamTest ); - -void IstreamTest::setUp() { -} +TEST_CASE ( "Istream", "[unit][std][bits]" ) { + SECTION ( "istream" ) { + std::stringstream ss ( "TEST" ); -void IstreamTest::tearDown() { -} + CHECK ( ( ( bool ) ( ss >> ext::string ( "TEST" ) ) ) == true ); -void IstreamTest::testIstream() { - std::stringstream ss ( "TEST" ); + ss.str ( "TEST" ); - CPPUNIT_ASSERT ( ( ( bool ) ( ss >> ext::string ( "TEST" ) ) ) == true ); + CHECK ( ( ( bool ) ( ss >> ext::string ( "TESS" ) ) ) == false ); + CHECK ( ss.str ( ) == "TEST" ); - ss.str ( "TEST" ); - CPPUNIT_ASSERT ( ( ( bool ) ( ss >> ext::string ( "TESS" ) ) ) == false ); - CPPUNIT_ASSERT ( ss.str ( ) == "TEST" ); - - - CPPUNIT_ASSERT ( ( ( bool ) ( ss >> ext::string ( "TESTS" ) ) ) == false ); - CPPUNIT_ASSERT ( ss.str ( ) == "TEST" ); + CHECK ( ( ( bool ) ( ss >> ext::string ( "TESTS" ) ) ) == false ); + CHECK ( ss.str ( ) == "TEST" ); + } } - diff --git a/alib2std/test-src/extensions/IstreamTest.h b/alib2std/test-src/extensions/IstreamTest.h deleted file mode 100644 index 5e61770846..0000000000 --- a/alib2std/test-src/extensions/IstreamTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef ISTREAM_TEST_H_ -#define ISTREAM_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class IstreamTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( IstreamTest ); - CPPUNIT_TEST( testIstream ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testIstream(); -}; - -#endif // ISTREAM_TEST_H_ diff --git a/alib2std/test-src/extensions/IteratorTest.cpp b/alib2std/test-src/extensions/IteratorTest.cpp index 12b0636704..b535706c74 100644 --- a/alib2std/test-src/extensions/IteratorTest.cpp +++ b/alib2std/test-src/extensions/IteratorTest.cpp @@ -1,4 +1,5 @@ -#include "IteratorTest.h" +#include <catch2/catch.hpp> + #include <alib/set> #include <alib/vector> #include <alib/pair> @@ -7,73 +8,66 @@ #include <alib/string> #include <alib/iterator> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( IteratorTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( IteratorTest ); - -void IteratorTest::setUp() { -} - -void IteratorTest::tearDown() { -} - -void IteratorTest::testIterator() { - std::vector < int * > data; +TEST_CASE ( "Iterator", "[unit][std][bits]" ) { + SECTION ( "Test Iterator" ) { + std::vector < int * > data; - data.push_back ( new int ( 1 ) ); - data.push_back ( new int ( 2 ) ); - data.push_back ( new int ( 3 ) ); - data.push_back ( new int ( 4 ) ); - data.push_back ( new int ( 5 ) ); + data.push_back ( new int ( 1 ) ); + data.push_back ( new int ( 2 ) ); + data.push_back ( new int ( 3 ) ); + data.push_back ( new int ( 4 ) ); + data.push_back ( new int ( 5 ) ); - std::vector < int > ref { 1, 2, 3, 4, 5 }; + std::vector < int > ref { 1, 2, 3, 4, 5 }; - bool res = std::equal ( ext::dereferencer ( data.begin ( ) ), ext::dereferencer ( data.end ( ) ), ref.begin ( ), ref.end ( ) ); - CPPUNIT_ASSERT ( res ); + bool res = std::equal ( ext::dereferencer ( data.begin ( ) ), ext::dereferencer ( data.end ( ) ), ref.begin ( ), ref.end ( ) ); + CHECK ( res ); - for ( int * elem : data ) { - delete elem; + for ( int * elem : data ) { + delete elem; + } } -} -void IteratorTest::testReverser() { - std::vector < int > data; + SECTION ( "Test Reverser" ) { + std::vector < int > data; - data.push_back ( 1 ); - data.push_back ( 2 ); - data.push_back ( 3 ); - data.push_back ( 4 ); - data.push_back ( 5 ); + data.push_back ( 1 ); + data.push_back ( 2 ); + data.push_back ( 3 ); + data.push_back ( 4 ); + data.push_back ( 5 ); - std::vector < int > data2; + std::vector < int > data2; - data2.push_back ( 5 ); - data2.push_back ( 4 ); - data2.push_back ( 3 ); - data2.push_back ( 2 ); - data2.push_back ( 1 ); + data2.push_back ( 5 ); + data2.push_back ( 4 ); + data2.push_back ( 3 ); + data2.push_back ( 2 ); + data2.push_back ( 1 ); - std::vector < int > trans; + std::vector < int > trans; - for ( int elem : ext::make_reverse ( data ) ) { - trans.push_back ( elem ); - } + for ( int elem : ext::make_reverse ( data ) ) { + trans.push_back ( elem ); + } - CPPUNIT_ASSERT ( data2 == trans ); + CHECK ( data2 == trans ); - const std::vector < int > & dataRef = data; - trans.clear ( ); + const std::vector < int > & dataRef = data; + trans.clear ( ); - for ( int elem : ext::make_reverse ( dataRef ) ) { - trans.push_back ( elem ); - } + for ( int elem : ext::make_reverse ( dataRef ) ) { + trans.push_back ( elem ); + } - CPPUNIT_ASSERT ( data2 == trans ); -} + CHECK ( data2 == trans ); + } -void IteratorTest::testCallbackIterator ( ) { - int expected; - ext::callback_iterator < int > out = ext::make_callback_iterator < int > ( [ & ] ( int value ) -> void { CPPUNIT_ASSERT ( value == expected ); } ); + SECTION ( "Test Callback Iterator" ) { + int expected; + ext::callback_iterator < int > out = ext::make_callback_iterator < int > ( [ & ] ( int value ) -> void { CHECK ( value == expected ); } ); - expected = 10; - * out = 10; + expected = 10; + * out = 10; + } } diff --git a/alib2std/test-src/extensions/IteratorTest.h b/alib2std/test-src/extensions/IteratorTest.h deleted file mode 100644 index 93d4bc4947..0000000000 --- a/alib2std/test-src/extensions/IteratorTest.h +++ /dev/null @@ -1,23 +0,0 @@ -#ifndef ITERATOR_TEST_H_ -#define ITERATOR_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class IteratorTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( IteratorTest ); - CPPUNIT_TEST( testIterator ); - CPPUNIT_TEST( testReverser ); - CPPUNIT_TEST( testCallbackIterator ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testIterator(); - void testReverser(); - void testCallbackIterator(); -}; - -#endif // ITERATOR_TEST_H_ diff --git a/alib2std/test-src/extensions/MemoryTest.cpp b/alib2std/test-src/extensions/MemoryTest.cpp index 5532a3e2e6..28a749425e 100644 --- a/alib2std/test-src/extensions/MemoryTest.cpp +++ b/alib2std/test-src/extensions/MemoryTest.cpp @@ -1,27 +1,21 @@ -#include "MemoryTest.h" +#include <catch2/catch.hpp> + #include <alib/compare> #include <alib/memory> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( MemoryTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( MemoryTest ); - -void MemoryTest::setUp ( ) { -} - -void MemoryTest::tearDown ( ) { -} - -void MemoryTest::comparePtrs ( ) { - std::shared_ptr < int > i = std::make_shared < int > ( 1 ); - std::shared_ptr < int > j = i; - std::shared_ptr < int > k = std::make_shared < int > ( 1 ); - std::shared_ptr < int > l; +TEST_CASE ( "Memory", "[unit][std][bits]" ) { + SECTION ( "Compare Pointers" ) { + std::shared_ptr < int > i = std::make_shared < int > ( 1 ); + std::shared_ptr < int > j = i; + std::shared_ptr < int > k = std::make_shared < int > ( 1 ); + std::shared_ptr < int > l; - ext::compare < std::shared_ptr < int > > comp; + ext::compare < std::shared_ptr < int > > comp; - CPPUNIT_ASSERT ( comp ( i, i ) == 0 ); - CPPUNIT_ASSERT ( comp ( i, j ) == 0 ); - CPPUNIT_ASSERT ( comp ( i, k ) == 0 ); - CPPUNIT_ASSERT ( comp ( i, l ) > 0 ); - CPPUNIT_ASSERT ( comp ( l, i ) < 0 ); + CHECK ( comp ( i, i ) == 0 ); + CHECK ( comp ( i, j ) == 0 ); + CHECK ( comp ( i, k ) == 0 ); + CHECK ( comp ( i, l ) > 0 ); + CHECK ( comp ( l, i ) < 0 ); + } } diff --git a/alib2std/test-src/extensions/MemoryTest.h b/alib2std/test-src/extensions/MemoryTest.h deleted file mode 100644 index 8df67731dd..0000000000 --- a/alib2std/test-src/extensions/MemoryTest.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MEMORY_TEST_H_ -#define MEMORY_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class MemoryTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( MemoryTest ); - CPPUNIT_TEST ( comparePtrs ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - void setUp ( ); - void tearDown ( ); - - void comparePtrs ( ); -}; - -#endif // MEMORY_TEST_H_ diff --git a/alib2std/test-src/extensions/OstreamTest.cpp b/alib2std/test-src/extensions/OstreamTest.cpp index fce12e48d1..8966bc053b 100644 --- a/alib2std/test-src/extensions/OstreamTest.cpp +++ b/alib2std/test-src/extensions/OstreamTest.cpp @@ -1,42 +1,34 @@ -#include "OstreamTest.h" +#include <catch2/catch.hpp> + #include <alib/set> #include <alib/vector> #include <alib/pair> #include <sstream> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( OstreamTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( OstreamTest ); - -void OstreamTest::setUp() { -} - -void OstreamTest::tearDown() { -} - -void OstreamTest::testOstream() { - ext::vector<int> vector1 {1, 2, 3}; - ext::vector<int> vector2 {2, 3, 4}; +TEST_CASE ( "Ostream", "[unit][std][bits]" ) { + SECTION ( "Test Ostream" ) { + ext::vector<int> vector1 {1, 2, 3}; + ext::vector<int> vector2 {2, 3, 4}; - std::stringstream ss1; - ss1 << vector1; - std::cout << ss1.str() << std::endl; - CPPUNIT_ASSERT("[1, 2, 3]" == ss1.str()); + std::stringstream ss1; + ss1 << vector1; + CAPTURE ( ss1.str ( ) ); + CHECK("[1, 2, 3]" == ss1.str()); - ext::set<ext::vector<int>> set1 {vector1}; - ext::set<ext::vector<int>> set2 {vector2}; + ext::set<ext::vector<int>> set1 {vector1}; + ext::set<ext::vector<int>> set2 {vector2}; - std::stringstream ss2; - ss2 << set1; - std::cout << ss2.str() << std::endl; - CPPUNIT_ASSERT("{[1, 2, 3]}" == ss2.str()); + std::stringstream ss2; + ss2 << set1; + CAPTURE ( ss2.str ( ) ); + CHECK("{[1, 2, 3]}" == ss2.str()); - ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>> pair1 {set1, set2}; - ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>> pair2 {set2, set1}; - - std::stringstream ss3; - ss3 << pair1; - std::cout << ss3.str() << std::endl; - CPPUNIT_ASSERT("({[1, 2, 3]}, {[2, 3, 4]})" == ss3.str()); + ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>> pair1 {set1, set2}; + ext::pair<ext::set<ext::vector<int>>, ext::set<ext::vector<int>>> pair2 {set2, set1}; + std::stringstream ss3; + ss3 << pair1; + CAPTURE ( ss3.str ( ) ); + CHECK("({[1, 2, 3]}, {[2, 3, 4]})" == ss3.str()); + } } - diff --git a/alib2std/test-src/extensions/OstreamTest.h b/alib2std/test-src/extensions/OstreamTest.h deleted file mode 100644 index c2cf462681..0000000000 --- a/alib2std/test-src/extensions/OstreamTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef OSTREAM_TEST_H_ -#define OSTREAM_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class OstreamTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( OstreamTest ); - CPPUNIT_TEST( testOstream ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testOstream(); -}; - -#endif // OSTREAM_TEST_H_ diff --git a/alib2std/test-src/extensions/ParamPassTest.cpp b/alib2std/test-src/extensions/ParamPassTest.cpp index 6e53f3a6fe..0f17c19a30 100644 --- a/alib2std/test-src/extensions/ParamPassTest.cpp +++ b/alib2std/test-src/extensions/ParamPassTest.cpp @@ -1,159 +1,152 @@ -#include "ParamPassTest.h" +#include <catch2/catch.hpp> + #include <exception> #include <alib/utility> #include <alib/memory> #include <alib/type_traits> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( ParamPassTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( ParamPassTest ); - -void ParamPassTest::setUp ( ) { -} - -void ParamPassTest::tearDown ( ) { -} - -int instances = 0; // set to expected number of instances created in parameter pass test including the original +namespace { + int instances = 0; // set to expected number of instances created in parameter pass test including the original -class FooCloneable { - int m_data; + class FooCloneable { + int m_data; - FooCloneable ( const FooCloneable & foo ) : m_data ( foo.m_data ) { - std::cout << "Copy" << std::endl; + FooCloneable ( const FooCloneable & foo ) : m_data ( foo.m_data ) { + //std::cout << "Copy" << std::endl; - instances++; - } + instances++; + } - FooCloneable ( FooCloneable && foo ) : m_data ( foo.m_data ) { - std::cout << "Move" << std::endl; + FooCloneable ( FooCloneable && foo ) : m_data ( foo.m_data ) { + //std::cout << "Move" << std::endl; - instances++; - } + instances++; + } -public: - FooCloneable ( int data ) : m_data ( data ) { - std::cout << "Constructor" << std::endl; + public: + FooCloneable ( int data ) : m_data ( data ) { + //std::cout << "Constructor" << std::endl; - instances++; - } + instances++; + } - ~FooCloneable ( ) { - std::cout << "Destructor" << std::endl; + ~FooCloneable ( ) { + //std::cout << "Destructor" << std::endl; - instances--; - } + instances--; + } - FooCloneable * clone ( ) const { - return new FooCloneable ( * this ); - } + FooCloneable * clone ( ) const { + return new FooCloneable ( * this ); + } - int getData ( ) const { - return m_data; - } + int getData ( ) const { + return m_data; + } -}; + }; -class FooCopyable { - int m_data; + class FooCopyable { + int m_data; -public: - FooCopyable ( int data ) : m_data ( data ) { - std::cout << "Constructor" << std::endl; + public: + FooCopyable ( int data ) : m_data ( data ) { + //std::cout << "Constructor" << std::endl; - instances++; - } + instances++; + } - FooCopyable ( const FooCopyable & foo ) : m_data ( foo.m_data ) { - std::cout << "Copy" << std::endl; + FooCopyable ( const FooCopyable & foo ) : m_data ( foo.m_data ) { + //std::cout << "Copy" << std::endl; - instances++; - } + instances++; + } - FooCopyable ( FooCopyable && foo ) : m_data ( foo.m_data ) { - std::cout << "Move" << std::endl; + FooCopyable ( FooCopyable && foo ) : m_data ( foo.m_data ) { + //std::cout << "Move" << std::endl; - instances++; - } + instances++; + } - ~FooCopyable ( ) { - std::cout << "Destructor" << std::endl; + ~FooCopyable ( ) { + //std::cout << "Destructor" << std::endl; - instances--; - } + instances--; + } - FooCopyable * clone ( ) const { - return new FooCopyable ( * this ); - } + FooCopyable * clone ( ) const { + return new FooCopyable ( * this ); + } - int getData ( ) const { - return m_data; - } + int getData ( ) const { + return m_data; + } -}; + }; -int dest ( FooCloneable && foo ) { - std::cout << "Destination called" << std::endl; + int dest ( FooCloneable && foo ) { + //std::cout << "Destination called" << std::endl; - CPPUNIT_ASSERT ( instances == 0 ); + CHECK ( instances == 0 ); - return foo.getData ( ); -} + return foo.getData ( ); + } -int dest ( FooCopyable && foo ) { - std::cout << "Destination called" << std::endl; + int dest ( FooCopyable && foo ) { + //std::cout << "Destination called" << std::endl; - CPPUNIT_ASSERT ( instances == 0 ); + CHECK ( instances == 0 ); - return foo.getData ( ); -} + return foo.getData ( ); + } -int test ( FooCloneable && foo ) { - return dest ( std::move ( foo ) ) + 1; -} + int test ( FooCloneable && foo ) { + return dest ( std::move ( foo ) ) + 1; + } -int test ( const FooCloneable & foo ) { - return test ( ext::move_copy ( foo ) ) + 1; -} + int test ( const FooCloneable & foo ) { + return test ( ext::move_copy ( foo ) ) + 1; + } -int test ( FooCopyable && foo ) { - return dest ( std::move ( foo ) ) + 1; -} + int test ( FooCopyable && foo ) { + return dest ( std::move ( foo ) ) + 1; + } -int test ( const FooCopyable & foo ) { - return test ( ext::move_copy ( foo ) ) + 1; + int test ( const FooCopyable & foo ) { + return test ( ext::move_copy ( foo ) ) + 1; + } } -void ParamPassTest::testParameterPassing ( ) { - { - instances = -2; - const FooCloneable foo ( 1 ); - int res = 0; - res = test ( foo ); - CPPUNIT_ASSERT ( res == 3 ); - } - std::cout << std::endl; - { - instances = -2; - const FooCopyable foo ( 1 ); - int res = 0; - res = test ( foo ); - CPPUNIT_ASSERT ( res == 3 ); - } - std::cout << std::endl; - { - instances = -2; - ext::ptr_value < FooCopyable > foo ( FooCopyable ( 1 ) ); - CPPUNIT_ASSERT ( instances == -1 ); - int res = 0; - res = test ( foo ); - CPPUNIT_ASSERT ( res == 3 ); - } - std::cout << std::endl; - { - instances = -1; - ext::ptr_value < FooCopyable > foo ( FooCopyable ( 1 ) ); - int res = 0; - res = test ( std::move ( foo ) ); - CPPUNIT_ASSERT ( res == 2 ); +TEST_CASE ( "ParamPass", "[unit][std][bits]" ) { + SECTION ( "Parameter Passing" ) { + { + instances = -2; + const FooCloneable foo ( 1 ); + int res = 0; + res = test ( foo ); + CHECK ( res == 3 ); + } + { + instances = -2; + const FooCopyable foo ( 1 ); + int res = 0; + res = test ( foo ); + CHECK ( res == 3 ); + } + { + instances = -2; + ext::ptr_value < FooCopyable > foo ( FooCopyable ( 1 ) ); + CHECK ( instances == -1 ); + int res = 0; + res = test ( foo ); + CHECK ( res == 3 ); + } + { + instances = -1; + ext::ptr_value < FooCopyable > foo ( FooCopyable ( 1 ) ); + int res = 0; + res = test ( std::move ( foo ) ); + CHECK ( res == 2 ); + } } } diff --git a/alib2std/test-src/extensions/ParamPassTest.h b/alib2std/test-src/extensions/ParamPassTest.h deleted file mode 100644 index 85a3ae69c9..0000000000 --- a/alib2std/test-src/extensions/ParamPassTest.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef PARAM_PASS_TEST_H_ -#define PARAM_PASS_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class ParamPassTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( ParamPassTest ); - CPPUNIT_TEST ( testParameterPassing ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - void setUp ( ); - void tearDown ( ); - - void testParameterPassing ( ); -}; - -#endif // PARAM_PASS_TEST_H_ diff --git a/alib2std/test-src/extensions/RandomTest.cpp b/alib2std/test-src/extensions/RandomTest.cpp index aedd29f5c5..c23c58ca5a 100644 --- a/alib2std/test-src/extensions/RandomTest.cpp +++ b/alib2std/test-src/extensions/RandomTest.cpp @@ -1,24 +1,17 @@ -#include "RandomTest.h" -#include <alib/random> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( RandomTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( RandomTest ); - -void RandomTest::setUp() { -} +#include <catch2/catch.hpp> -void RandomTest::tearDown() { -} +#include <alib/random> -void RandomTest::testRandom() { - std::cout << ext::random_devices::random() << std::endl; - std::cout << ext::random_devices::semirandom() << std::endl; +TEST_CASE ( "Random", "[unit][std][bits]" ) { + SECTION ( "Test Random" ) { + CAPTURE ( ext::random_devices::random(), ext::random_devices::semirandom() ); - ext::random_devices::semirandom.seed ( 100 ); - unsigned first = ext::random_devices::semirandom(); - ext::random_devices::semirandom.seed ( 100 ); - unsigned second = ext::random_devices::semirandom(); + ext::random_devices::semirandom.seed ( 100 ); + unsigned first = ext::random_devices::semirandom(); + ext::random_devices::semirandom.seed ( 100 ); + unsigned second = ext::random_devices::semirandom(); - CPPUNIT_ASSERT( first == second ); + CHECK( first == second ); + } } diff --git a/alib2std/test-src/extensions/RandomTest.h b/alib2std/test-src/extensions/RandomTest.h deleted file mode 100644 index db0feec9ea..0000000000 --- a/alib2std/test-src/extensions/RandomTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef RANDOM_TEST_H_ -#define RANDOM_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class RandomTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( RandomTest ); - CPPUNIT_TEST( testRandom ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testRandom(); -}; - -#endif // RANDOM_TEST_H_ diff --git a/alib2std/test-src/extensions/RangeTest.cpp b/alib2std/test-src/extensions/RangeTest.cpp index a9f5182e66..9ec4bca19a 100644 --- a/alib2std/test-src/extensions/RangeTest.cpp +++ b/alib2std/test-src/extensions/RangeTest.cpp @@ -1,82 +1,74 @@ -#include "RangeTest.h" +#include <catch2/catch.hpp> + #include <alib/range> #include <alib/vector> #include <alib/list> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( RangeTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( RangeTest ); - -void RangeTest::setUp ( ) { -} - -void RangeTest::tearDown ( ) { -} - -void RangeTest::constructorTest ( ) { +TEST_CASE ( "Range", "[unit][std][bits]" ) { int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - ext::iterator_range < int * > ra1 = ext::range ( arr ); + SECTION ( "Constructor" ) { + ext::iterator_range < int * > ra1 = ext::range ( arr ); - ext::vector < int > v1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + ext::vector < int > v1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - ext::iterator_range < ext::vector < int >::iterator > rv1 ( v1.begin ( ), v1.end ( ) ); + ext::iterator_range < ext::vector < int >::iterator > rv1 ( v1.begin ( ), v1.end ( ) ); - CPPUNIT_ASSERT ( ( std::equal ( ra1.begin ( ), ra1.end ( ), rv1.begin ( ), rv1.end ( ) ) ) ); + CHECK ( ( std::equal ( ra1.begin ( ), ra1.end ( ), rv1.begin ( ), rv1.end ( ) ) ) ); - auto rv2 = ext::range ( v1 ); + auto rv2 = ext::range ( v1 ); - CPPUNIT_ASSERT ( ( std::equal ( rv1.begin ( ), rv1.end ( ), rv2.begin ( ), rv2.end ( ) ) ) ); -} + CHECK ( ( std::equal ( rv1.begin ( ), rv1.end ( ), rv2.begin ( ), rv2.end ( ) ) ) ); + } -void RangeTest::sizeTest ( ) { - int arr[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + SECTION ( "Size" ) { + ext::iterator_range < int * > ra1 ( arr, arr + sizeof ( arr ) / sizeof ( * arr ) ); - ext::iterator_range < int * > ra1 ( arr, arr + sizeof ( arr ) / sizeof ( * arr ) ); + CHECK ( ra1.size ( ) == 10 ); - CPPUNIT_ASSERT ( ra1.size ( ) == 10 ); + ext::vector < int > v1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - ext::vector < int > v1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + ext::iterator_range < ext::vector < int >::iterator > rv1 ( v1.begin ( ), v1.end ( ) ); - ext::iterator_range < ext::vector < int >::iterator > rv1 ( v1.begin ( ), v1.end ( ) ); + CHECK ( rv1.size ( ) == 10 ); - CPPUNIT_ASSERT ( rv1.size ( ) == 10 ); + ext::list < int > l1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - ext::list < int > l1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + ext::iterator_range < ext::list < int >::iterator > rl1 ( l1.begin ( ), l1.end ( ) ); - ext::iterator_range < ext::list < int >::iterator > rl1 ( l1.begin ( ), l1.end ( ) ); + CHECK ( rl1.size ( ) == 10 ); + } - CPPUNIT_ASSERT ( rl1.size ( ) == 10 ); -} + SECTION ( "Split" ) { + ext::vector < int > v1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; -void RangeTest::splitTest ( ) { - ext::vector < int > v1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + auto r1 = ext::range ( v1 ); - auto r1 = ext::range ( v1 ); + ext::vector < int > v2 = { 0, 1, 2 }; - ext::vector < int > v2 = { 0, 1, 2 }; + auto r2 = ext::range ( v2 ); - auto r2 = ext::range ( v2 ); + ext::vector < int > v3 = { 3, 4, 5, 6, 7, 8, 9 }; - ext::vector < int > v3 = { 3, 4, 5, 6, 7, 8, 9 }; + auto r3 = ext::range ( v3 ); - auto r3 = ext::range ( v3 ); + auto splitted = r1.split ( 3 ); - auto splitted = r1.split ( 3 ); - - CPPUNIT_ASSERT ( ( std::equal ( splitted.first.begin ( ), splitted.first.end ( ), r2.begin ( ), r2.end ( ) ) ) ); - CPPUNIT_ASSERT ( ( std::equal ( splitted.second.begin ( ), splitted.second.end ( ), r3.begin ( ), r3.end ( ) ) ) ); -} + CHECK ( ( std::equal ( splitted.first.begin ( ), splitted.first.end ( ), r2.begin ( ), r2.end ( ) ) ) ); + CHECK ( ( std::equal ( splitted.second.begin ( ), splitted.second.end ( ), r3.begin ( ), r3.end ( ) ) ) ); + } -void RangeTest::sliceTest ( ) { - ext::vector < int > v1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; + SECTION ( "Slice" ) { + ext::vector < int > v1 = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; - auto r1 = ext::range ( v1 ); + auto r1 = ext::range ( v1 ); - ext::vector < int > v2 = { 4, 5, 6 }; + ext::vector < int > v2 = { 4, 5, 6 }; - auto r2 = ext::range ( v2 ); + auto r2 = ext::range ( v2 ); - auto sliced = r1.slice ( 4, -3 ); + auto sliced = r1.slice ( 4, -3 ); - CPPUNIT_ASSERT ( ( std::equal ( sliced.begin ( ), sliced.end ( ), r2.begin ( ), r2.end ( ) ) ) ); + CHECK ( ( std::equal ( sliced.begin ( ), sliced.end ( ), r2.begin ( ), r2.end ( ) ) ) ); + } } diff --git a/alib2std/test-src/extensions/RangeTest.h b/alib2std/test-src/extensions/RangeTest.h deleted file mode 100644 index e4cd64b6fc..0000000000 --- a/alib2std/test-src/extensions/RangeTest.h +++ /dev/null @@ -1,24 +0,0 @@ -#ifndef RANGE_TEST_H_ -#define RANGE_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class RangeTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( RangeTest ); - CPPUNIT_TEST ( constructorTest ); - CPPUNIT_TEST ( sizeTest ); - CPPUNIT_TEST ( splitTest ); - CPPUNIT_TEST ( sliceTest ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - void setUp ( ); - void tearDown ( ); - - void constructorTest ( ); - void sizeTest ( ); - void splitTest ( ); - void sliceTest ( ); -}; - -#endif // RANGE_TEST_H_ diff --git a/alib2std/test-src/extensions/SharedPtrTest.cpp b/alib2std/test-src/extensions/SharedPtrTest.cpp index d59e7adb5e..3d4163404d 100644 --- a/alib2std/test-src/extensions/SharedPtrTest.cpp +++ b/alib2std/test-src/extensions/SharedPtrTest.cpp @@ -1,96 +1,156 @@ -#include "SharedPtrTest.h" -#include <alib/utility> +#include <catch2/catch.hpp> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SharedPtrTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( SharedPtrTest ); +#include <alib/memory> +#include <alib/utility> -void SharedPtrTest::setUp() { +namespace { + class Moveable { + int& m_moves; + int& m_copies; + + public: + Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { + m_moves = 0; + m_copies = 0; + } + + Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_copies++; + } + + Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_moves++; + } + + bool operator<(const Moveable&) const { + return false; + } + }; + + class Moveable2 { + int& m_moves; + int& m_copies; + + public: + Moveable2(int& moves, int& copies) : m_moves(moves), m_copies(copies) { + m_moves = 0; + m_copies = 0; + } + + Moveable2(const Moveable2& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_copies++; + } + + Moveable2(Moveable2&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_moves++; + } + + bool operator<(const Moveable2&) const { + return false; + } + }; + + class Base { + public: + virtual Base* clone() const = 0; + + virtual ~Base ( ) { + } + }; + + class Derived : public Base { + public: + virtual Derived* clone() const override { + return new Derived(*this); + } + + virtual ~Derived ( ) override { + } + }; } +TEST_CASE ( "Shared Ptr", "[unit][std][bits]" ) { + SECTION ( "Shared Ptr" ) { + { + int moves; + int copies; -void SharedPtrTest::tearDown() { -} + ext::cow_shared_ptr<Moveable> one(new Moveable(moves, copies)); -void SharedPtrTest::testSharedPtr1() { - int moves; - int copies; + CHECK(one.unique()); + CHECK(moves == 0); + CHECK(copies == 0); - ext::cow_shared_ptr<SharedPtrTest::Moveable> one(new SharedPtrTest::Moveable(moves, copies)); + ext::cow_shared_ptr<Moveable> two(one); - CPPUNIT_ASSERT(one.unique()); - CPPUNIT_ASSERT(moves == 0); - CPPUNIT_ASSERT(copies == 0); + CHECK(!one.unique()); + CHECK(moves == 0); + CHECK(copies == 0); - ext::cow_shared_ptr<SharedPtrTest::Moveable> two(one); + std::as_const(two).get(); - CPPUNIT_ASSERT(!one.unique()); - CPPUNIT_ASSERT(moves == 0); - CPPUNIT_ASSERT(copies == 0); + ext::cow_shared_ptr<Moveable> three(std::move ( two ) ); - std::as_const(two).get(); + std::as_const(three).get(); - ext::cow_shared_ptr<SharedPtrTest::Moveable> three(std::move ( two ) ); + CHECK(!one.unique()); + CHECK(moves == 0); + CHECK(copies == 0); - std::as_const(three).get(); + two = std::move ( three ) ; - CPPUNIT_ASSERT(!one.unique()); - CPPUNIT_ASSERT(moves == 0); - CPPUNIT_ASSERT(copies == 0); + two.get(); - two = std::move ( three ) ; + CHECK(one.unique()); + CHECK(moves == 0); + CHECK(copies == 1); + } + { - two.get(); + int moves; + int copies; - CPPUNIT_ASSERT(one.unique()); - CPPUNIT_ASSERT(moves == 0); - CPPUNIT_ASSERT(copies == 1); -} + ext::cow_shared_ptr<Moveable2> one(new Moveable2(moves, copies)); -void SharedPtrTest::testSharedPtr2() { - int moves; - int copies; + CHECK(one.unique()); + CHECK(moves == 0); + CHECK(copies == 0); - ext::cow_shared_ptr<SharedPtrTest::Moveable2> one(new SharedPtrTest::Moveable2(moves, copies)); + ext::cow_shared_ptr<Moveable2> two(one); - CPPUNIT_ASSERT(one.unique()); - CPPUNIT_ASSERT(moves == 0); - CPPUNIT_ASSERT(copies == 0); + CHECK(!one.unique()); + CHECK(moves == 0); + CHECK(copies == 0); - ext::cow_shared_ptr<SharedPtrTest::Moveable2> two(one); + std::as_const(two).get(); - CPPUNIT_ASSERT(!one.unique()); - CPPUNIT_ASSERT(moves == 0); - CPPUNIT_ASSERT(copies == 0); + ext::cow_shared_ptr<Moveable2> three(std::move ( two ) ); - std::as_const(two).get(); + std::as_const(three).get(); - ext::cow_shared_ptr<SharedPtrTest::Moveable2> three(std::move ( two ) ); + CHECK(!one.unique()); + CHECK(moves == 0); + CHECK(copies == 0); - std::as_const(three).get(); + two = std::move ( three ) ; - CPPUNIT_ASSERT(!one.unique()); - CPPUNIT_ASSERT(moves == 0); - CPPUNIT_ASSERT(copies == 0); + two.get(); - two = std::move ( three ) ; + CHECK(one.unique()); + CHECK(moves == 0); + CHECK(copies == 1); + } + { + ext::cow_shared_ptr<Base> one(new Derived()); + ext::cow_shared_ptr<Base> two(one); - two.get(); + CHECK(!one.unique()); - CPPUNIT_ASSERT(one.unique()); - CPPUNIT_ASSERT(moves == 0); - CPPUNIT_ASSERT(copies == 1); -} + two.get(); -void SharedPtrTest::testSharedPtr3() { - ext::cow_shared_ptr<SharedPtrTest::Base> one(new SharedPtrTest::Derived()); - ext::cow_shared_ptr<SharedPtrTest::Base> two(one); + CHECK(one.unique()); + CHECK(two.unique()); - CPPUNIT_ASSERT(!one.unique()); - - two.get(); - - CPPUNIT_ASSERT(one.unique()); - CPPUNIT_ASSERT(two.unique()); - - CPPUNIT_ASSERT(one.get() != two.get()); + CHECK(one.get() != two.get()); + } + } } - diff --git a/alib2std/test-src/extensions/SharedPtrTest.h b/alib2std/test-src/extensions/SharedPtrTest.h deleted file mode 100644 index 2ed9aa6f7f..0000000000 --- a/alib2std/test-src/extensions/SharedPtrTest.h +++ /dev/null @@ -1,89 +0,0 @@ -#ifndef TYPE_TRAITS_TEST_H_ -#define TYPE_TRAITS_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/memory> - -class SharedPtrTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( SharedPtrTest ); - CPPUNIT_TEST( testSharedPtr1 ); - CPPUNIT_TEST( testSharedPtr2 ); - CPPUNIT_TEST( testSharedPtr3 ); - CPPUNIT_TEST_SUITE_END(); - -public: -class Moveable { - int& m_moves; - int& m_copies; - -public: - Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { - m_moves = 0; - m_copies = 0; - } - - Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_copies++; - } - - Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_moves++; - } - - bool operator<(const Moveable&) const { - return false; - } -}; - -class Moveable2 { - int& m_moves; - int& m_copies; - -public: - Moveable2(int& moves, int& copies) : m_moves(moves), m_copies(copies) { - m_moves = 0; - m_copies = 0; - } - - Moveable2(const Moveable2& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_copies++; - } - - Moveable2(Moveable2&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_moves++; - } - - bool operator<(const Moveable2&) const { - return false; - } -}; - -class Base { -public: - virtual Base* clone() const = 0; - - virtual ~Base ( ) { - } -}; - -class Derived : public Base { -public: - virtual Derived* clone() const override { - return new Derived(*this); - } - - virtual ~Derived ( ) override { - } -}; - -public: - void setUp(); - void tearDown(); - - void testSharedPtr1(); - void testSharedPtr2(); - void testSharedPtr3(); -}; - -#endif // TYPE_TRAITS_TEST_H_ diff --git a/alib2std/test-src/extensions/TypeInfoTest.cpp b/alib2std/test-src/extensions/TypeInfoTest.cpp index 616b82d1b4..ec81bf3e69 100644 --- a/alib2std/test-src/extensions/TypeInfoTest.cpp +++ b/alib2std/test-src/extensions/TypeInfoTest.cpp @@ -1,71 +1,78 @@ -#include "TypeInfoTest.h" +#include <catch2/extensions/HelperMacros.h> + #include <alib/string> #include <alib/iostream> #include <alib/typeinfo> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TypeInfoTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( TypeInfoTest ); +namespace { + class Base { + public: + virtual ~Base() {} + }; -void TypeInfoTest::setUp() { -} + class Child1 : public Base { + }; -void TypeInfoTest::tearDown() { + class Child2 : public Base { + }; } -void TypeInfoTest::testTypeInfo() { - Child1 c1; - Child2 c2; +TEST_CASE ( "TypeInfo", "[unit][std][bits]" ) { + SECTION ( "Type Info" ) { + Child1 c1; + Child2 c2; - Child1& c1r = c1; - Child2& c2r = c2; + Child1& c1r = c1; + Child2& c2r = c2; - Base& c1br = c1r; - Base& c2br = c2r; + Base& c1br = c1r; + Base& c2br = c2r; - Child1* c1p = &c1; - Child2* c2p = &c2; + Child1* c1p = &c1; + Child2* c2p = &c2; - Base* c1bp = c1p; - Base* c2bp = c2p; + Base* c1bp = c1p; + Base* c2bp = c2p; - const std::type_info& c1Type = typeid(c1); - const std::type_info& c2Type = typeid(c2); + const std::type_info& c1Type = typeid(c1); + const std::type_info& c2Type = typeid(c2); - const std::type_info& c1rType = typeid(c1r); - const std::type_info& c2rType = typeid(c2r); + const std::type_info& c1rType = typeid(c1r); + const std::type_info& c2rType = typeid(c2r); - const std::type_info& c1brType = typeid(c1br); - const std::type_info& c2brType = typeid(c2br); + const std::type_info& c1brType = typeid(c1br); + const std::type_info& c2brType = typeid(c2br); - const std::type_info& c1pType = typeid(c1p); - const std::type_info& c2pType = typeid(c2p); + const std::type_info& c1pType = typeid(c1p); + const std::type_info& c2pType = typeid(c2p); - const std::type_info& c1bpType = typeid(c1bp); - const std::type_info& c2bpType = typeid(c2bp); + const std::type_info& c1bpType = typeid(c1bp); + const std::type_info& c2bpType = typeid(c2bp); -/* std::cout << c1Type.name() << " " << c2Type.name() << std::endl; - std::cout << c1rType.name() << " " << c2rType.name() << std::endl; - std::cout << c1brType.name() << " " << c2brType.name() << std::endl; - std::cout << c1pType.name() << " " << c2pType.name() << std::endl; - std::cout << c1bpType.name() << " " << c2bpType.name() << std::endl;*/ + /* std::cout << c1Type.name() << " " << c2Type.name() << std::endl; + std::cout << c1rType.name() << " " << c2rType.name() << std::endl; + std::cout << c1brType.name() << " " << c2brType.name() << std::endl; + std::cout << c1pType.name() << " " << c2pType.name() << std::endl; + std::cout << c1bpType.name() << " " << c2bpType.name() << std::endl;*/ - CPPUNIT_EXCLUSIVE_OR(c1Type.before (c2Type ), c2Type.before (c1Type )); - CPPUNIT_EXCLUSIVE_OR(c1rType.before (c2rType ), c2rType.before (c1rType )); - CPPUNIT_EXCLUSIVE_OR(c1brType.before(c2brType), c2brType.before(c1brType)); - CPPUNIT_EXCLUSIVE_OR(c1pType.before (c2pType ), c2pType.before (c1pType )); - CPPUNIT_ASSERT(c1bpType == c2bpType); + CHECK_EXCLUSIVE_OR(c1Type.before (c2Type ), c2Type.before (c1Type )); + CHECK_EXCLUSIVE_OR(c1rType.before (c2rType ), c2rType.before (c1rType )); + CHECK_EXCLUSIVE_OR(c1brType.before(c2brType), c2brType.before(c1brType)); + CHECK_EXCLUSIVE_OR(c1pType.before (c2pType ), c2pType.before (c1pType )); + CHECK(c1bpType == c2bpType); - CPPUNIT_ASSERT(c1Type == c1rType); - CPPUNIT_ASSERT(c1Type == c1brType); - CPPUNIT_ASSERT(c1Type != c1pType); - CPPUNIT_ASSERT(c1Type != c1bpType); - CPPUNIT_ASSERT(c2Type == c2rType); - CPPUNIT_ASSERT(c2Type == c2brType); - CPPUNIT_ASSERT(c2Type != c2pType); - CPPUNIT_ASSERT(c2Type != c2bpType); -} + CHECK(c1Type == c1rType); + CHECK(c1Type == c1brType); + CHECK(c1Type != c1pType); + CHECK(c1Type != c1bpType); + CHECK(c2Type == c2rType); + CHECK(c2Type == c2brType); + CHECK(c2Type != c2pType); + CHECK(c2Type != c2bpType); + } -void TypeInfoTest::testGetTemplateInfo() { - ext::vector < std::string > templateInfo = ext::get_template_info ( "bar::Foo < int >::Baz < foo::Foo < bar > >" ); - std::cout << templateInfo << std::endl; + SECTION ( "Get Template Info" ) { + ext::vector < std::string > templateInfo = ext::get_template_info ( "bar::Foo < int >::Baz < foo::Foo < bar > >" ); + CHECK ( templateInfo == std::vector < std::string > { "int", "foo::Foo < bar >" } ); + } } diff --git a/alib2std/test-src/extensions/TypeInfoTest.h b/alib2std/test-src/extensions/TypeInfoTest.h deleted file mode 100644 index 07474af87e..0000000000 --- a/alib2std/test-src/extensions/TypeInfoTest.h +++ /dev/null @@ -1,32 +0,0 @@ -#ifndef TYPE_INFO_TEST_H_ -#define TYPE_INFO_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class TypeInfoTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( TypeInfoTest ); - CPPUNIT_TEST( testTypeInfo ); - CPPUNIT_TEST( testGetTemplateInfo ); - CPPUNIT_TEST_SUITE_END(); - - class Base { - public: - virtual ~Base() {} - }; - - class Child1 : public Base { - }; - - class Child2 : public Base { - }; - -public: - void setUp(); - void tearDown(); - - void testTypeInfo(); - void testGetTemplateInfo(); -}; - -#endif // TYPE_INFO_TEST_H_ diff --git a/alib2std/test-src/extensions/TypeTraitsTest.cpp b/alib2std/test-src/extensions/TypeTraitsTest.cpp index d92457fcf0..cf086ef7a1 100644 --- a/alib2std/test-src/extensions/TypeTraitsTest.cpp +++ b/alib2std/test-src/extensions/TypeTraitsTest.cpp @@ -1,44 +1,39 @@ -#include "TypeTraitsTest.h" +#include <catch2/catch.hpp> + #include <alib/type_traits> #include <alib/set> #include <alib/pair> #include <alib/typeinfo> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TypeTraitsTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( TypeTraitsTest ); - -void TypeTraitsTest::setUp() { -} - -void TypeTraitsTest::tearDown() { -} - -void TypeTraitsTest::testTypeInPack() { - CPPUNIT_ASSERT( ( ext::is_in< int, double, ext::set<int>, float, char, int, std::string >::value ) == true ); - CPPUNIT_ASSERT( ( ext::is_in< long, double, ext::set<int>, float, char, int, std::string >::value ) == false ); +namespace ns { + class Foo { + }; - CPPUNIT_ASSERT( ( ext::is_in< std::pair < int, int >, void, ext::pair < int, int > >::value ) == false ); -} - -class Foo { -}; - -class Bar; - -void TypeTraitsTest::testTypeNames() { - CPPUNIT_ASSERT ( ext::to_string < Foo > ( ) == "Foo" ); - CPPUNIT_ASSERT ( ext::to_string < Bar > ( ) == "Bar" ); - CPPUNIT_ASSERT ( ext::to_string < int > ( ) == "int" ); -} + class Bar; -bool operator < ( const Foo &, int ) { - return false; + bool operator < ( const Foo &, int ) { + return false; + } } -void TypeTraitsTest::testSupports() { - CPPUNIT_ASSERT ( ext::supports < std::less < > ( int, int ) >::value == true ); - CPPUNIT_ASSERT ( ext::supports < std::less < > ( unsigned, int ) >::value == true ); - CPPUNIT_ASSERT ( ext::supports < std::less < > ( double, char ) >::value == true ); - CPPUNIT_ASSERT ( ext::supports < std::less < > ( Foo, char ) >::value == true ); - CPPUNIT_ASSERT ( ext::supports < std::less < > ( Foo, Foo ) >::value == false ); +TEST_CASE ( "TypeTraits", "[unit][std][bits]" ) { + SECTION ( "Type in pack" ) { + CHECK( ( ext::is_in< int, double, ext::set<int>, float, char, int, std::string >::value ) == true ); + CHECK( ( ext::is_in< long, double, ext::set<int>, float, char, int, std::string >::value ) == false ); + CHECK( ( ext::is_in< std::pair < int, int >, void, ext::pair < int, int > >::value ) == false ); + } + + SECTION ( "Type Names" ) { + CHECK ( ext::to_string < ns::Foo > ( ) == "ns::Foo" ); + CHECK ( ext::to_string < ns::Bar > ( ) == "ns::Bar" ); + CHECK ( ext::to_string < int > ( ) == "int" ); + } + + SECTION ( "Test Supports" ) { + CHECK ( ext::supports < std::less < > ( int, int ) >::value == true ); + CHECK ( ext::supports < std::less < > ( unsigned, int ) >::value == true ); + CHECK ( ext::supports < std::less < > ( double, char ) >::value == true ); + CHECK ( ext::supports < std::less < > ( ns::Foo, char ) >::value == true ); + CHECK ( ext::supports < std::less < > ( ns::Foo, ns::Foo ) >::value == false ); + } } diff --git a/alib2std/test-src/extensions/TypeTraitsTest.h b/alib2std/test-src/extensions/TypeTraitsTest.h deleted file mode 100644 index 3ef045b9ec..0000000000 --- a/alib2std/test-src/extensions/TypeTraitsTest.h +++ /dev/null @@ -1,22 +0,0 @@ -#ifndef TYPE_TRAITS_TEST_H_ -#define TYPE_TRAITS_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class TypeTraitsTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE( TypeTraitsTest ); - CPPUNIT_TEST( testTypeInPack ); - CPPUNIT_TEST( testTypeNames ); - CPPUNIT_TEST( testSupports ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testTypeInPack(); - void testTypeNames(); - void testSupports(); -}; - -#endif // TYPE_TRAITS_TEST_H_ diff --git a/alib2std/test-src/extensions/UtilityTest.cpp b/alib2std/test-src/extensions/UtilityTest.cpp index d061c9aee4..866d111496 100644 --- a/alib2std/test-src/extensions/UtilityTest.cpp +++ b/alib2std/test-src/extensions/UtilityTest.cpp @@ -1,24 +1,19 @@ -#include "UtilityTest.h" -#include <alib/utility> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( UtilityTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( UtilityTest ); +#include <catch2/catch.hpp> -void UtilityTest::setUp() { -} +#include <alib/utility> -void UtilityTest::tearDown() { +namespace { + class Foo { + public: + int bar ( ) { + return 1; + } + }; } -class Foo { -public: - int bar ( ) { - return 1; +TEST_CASE ( "Utility", "[unit][std][bits]" ) { + SECTION ( "Test Properties" ) { + ext::ptr_value < Foo > val ( Foo { } ); + CHECK ( val->bar ( ) == 1 ); } -}; - -void UtilityTest::testProperties() { - ext::ptr_value < Foo > val ( Foo { } ); - CPPUNIT_ASSERT ( val->bar ( ) == 1 ); } - diff --git a/alib2std/test-src/extensions/UtilityTest.h b/alib2std/test-src/extensions/UtilityTest.h deleted file mode 100644 index a04660a513..0000000000 --- a/alib2std/test-src/extensions/UtilityTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef UTILITY_TEST_H_ -#define UTILITY_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class UtilityTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( UtilityTest ); - CPPUNIT_TEST( testProperties ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testProperties(); -}; - -#endif // UTILITY_TEST_H_ diff --git a/alib2std/test-src/extensions/container/ArrayTest.cpp b/alib2std/test-src/extensions/container/ArrayTest.cpp index f7daaa4f96..ff58cf9049 100644 --- a/alib2std/test-src/extensions/container/ArrayTest.cpp +++ b/alib2std/test-src/extensions/container/ArrayTest.cpp @@ -1,24 +1,15 @@ -#include "ArrayTest.h" +#include <catch2/catch.hpp> #include <alib/map> #include <alib/algorithm> #include <alib/array> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( ArrayTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( ArrayTest ); +TEST_CASE ( "Array", "[unit][std][container]" ) { + SECTION ( "Basic" ) { + ext::array < int, 3 > a = ext::make_array ( 1, 2, 3 ); + CHECK ( a [ 0 ] == 1 ); -void ArrayTest::setUp() { -} - -void ArrayTest::tearDown() { -} - -void ArrayTest::basicTest() { - ext::array < int, 3 > a = ext::make_array ( 1, 2, 3 ); - - CPPUNIT_ASSERT ( a [ 0 ] == 1 ); - - ext::array < int, 3 > b = a; - - CPPUNIT_ASSERT ( b [ 1 ] == a [ 1 ] ); + ext::array < int, 3 > b = a; + CHECK ( b [ 1 ] == a [ 1 ] ); + } } diff --git a/alib2std/test-src/extensions/container/ArrayTest.h b/alib2std/test-src/extensions/container/ArrayTest.h deleted file mode 100644 index 0a5b916173..0000000000 --- a/alib2std/test-src/extensions/container/ArrayTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef ARRAY_TEST_H_ -#define ARRAY_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class ArrayTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( ArrayTest ); - CPPUNIT_TEST( basicTest ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void basicTest(); -}; - -#endif // ARRAY_TEST_H_ diff --git a/alib2std/test-src/extensions/container/ForwardTreeTest.cpp b/alib2std/test-src/extensions/container/ForwardTreeTest.cpp index 73ead92db8..e2c8f55ece 100644 --- a/alib2std/test-src/extensions/container/ForwardTreeTest.cpp +++ b/alib2std/test-src/extensions/container/ForwardTreeTest.cpp @@ -1,115 +1,126 @@ -#include "ForwardTreeTest.h" +#include <catch2/catch.hpp> #include <alib/vector> #include <alib/deque> #include <alib/tuple> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( ForwardTreeTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( ForwardTreeTest ); - -void ForwardTreeTest::setUp ( ) { -} - -void ForwardTreeTest::tearDown ( ) { -} - -void ForwardTreeTest::print_tree ( const ext::forward_tree < char > & tree, std::string indent ) { - std::cout << indent << tree.getData ( ) << std::endl; - for ( const ext::forward_tree < char > & child : tree.getChildren ( ) ) { - print_tree ( child, indent + " " ); +#include <alib/compare> +#include <alib/forward_tree> + +namespace { + struct RankedArityChecker { + bool operator ()( char symbol, unsigned wantedRank ) const { + switch ( symbol ) { + case 'a': + return wantedRank == 2; + + case 'b': + return wantedRank == 1; + + default: + return wantedRank == 0; + } + } + + }; + + static void print_tree ( const ext::forward_tree < char > & tree, std::string indent ) { + std::cout << indent << tree.getData ( ) << std::endl; + for ( const ext::forward_tree < char > & child : tree.getChildren ( ) ) { + print_tree ( child, indent + " " ); + } } } - -void ForwardTreeTest::testTreeStdStructure ( ) { - ext::forward_tree < char > t ( 'a', ext::forward_tree < char > ( 'a' ), ext::forward_tree < char > ( 'b', ext::forward_tree < char > ( 'a' ), ext::forward_tree < char > ( 'b' ) ) ); - - ext::forward_tree < char > t2 ( 'c' ); - - t2.insert ( t2.begin ( ), { 'c', ext::forward_tree < char > ( 'b' ) } ); - - std::swap ( t2.getChildren ( ).front (), t.getChildren().front ( ) ); - CPPUNIT_ASSERT ( t2 == ext::forward_tree < char > ( 'c', ext::forward_tree < char > ( 'a' ) ) ); - CPPUNIT_ASSERT ( t == ext::forward_tree < char > ( 'a', ext::forward_tree < char > ( 'c', ext::forward_tree < char > ( 'b' ) ), ext::forward_tree < char > ( 'b', ext::forward_tree < char > ( 'a' ), ext::forward_tree < char > ( 'b' ) ) ) ); - std::swap ( t2.getChildren ( ).front (), t.getChildren().front ( ) ); - - t2.insert ( t2.end ( ), t ); - - ext::vector < char > data = { 'd', 'e' }; - t2.insert ( t2.end ( ), data.begin ( ), data.end ( ) ); - - print_tree ( t, ""); - - t2.erase ( std::prev ( t2.end ( ) ) ); - t2.push_back ( 'f' ); - - print_tree ( t2, ""); - - CPPUNIT_ASSERT_EQUAL ( ( char ) t2 ( 1, 1 ), 'b' ); - t2 ( 1, 1 ) = 'c'; - CPPUNIT_ASSERT_EQUAL ( ( char ) t2 ( 1, 1 ), 'c' ); - - ext::forward_tree < char >::const_prefix_iterator beg = t2.prefix_begin ( ); - beg++; - beg++; - beg++; - beg++; - beg++; - beg++; - beg++; - beg--; - beg--; - beg--; - beg--; - beg--; - beg--; - beg--; - - CPPUNIT_ASSERT ( beg == t2.prefix_begin ( ) ); - std::cout << t2 << std::endl; - std::stringstream ss; - ss << t2; - CPPUNIT_ASSERT ( ss.str ( ) == "[0c[1c[2b],1a[2a,2c[3a,3b]],1d,1f]]" ); - - ext::vector < std::pair < unsigned, char > > expectedPrefix = { { 0, 'c' }, { 1, 'c' }, { 2, 'b' }, { 1, 'a' }, { 2, 'a' }, { 2, 'c' }, { 3, 'a' }, { 3, 'b' }, { 1, 'd' }, { 1, 'f' } }; - ext::vector < std::pair < unsigned, char > >::const_iterator ref = expectedPrefix.begin ( ); - - for ( ext::forward_tree < char >::const_prefix_iterator iter = t2.prefix_begin ( ); iter != t2.prefix_end ( ); ++iter ) { - CPPUNIT_ASSERT ( iter.getLevel ( ) == ref->first ); - CPPUNIT_ASSERT ( * iter == ref->second ); - ++iter; - --iter; - ++ref; +TEST_CASE ( "Forward Tree", "[unit][std][container]" ) { + SECTION ( "Tree Std Structure" ) { + ext::forward_tree < char > t ( 'a', ext::forward_tree < char > ( 'a' ), ext::forward_tree < char > ( 'b', ext::forward_tree < char > ( 'a' ), ext::forward_tree < char > ( 'b' ) ) ); + ext::forward_tree < char > t2 ( 'c' ); + + t2.insert ( t2.begin ( ), { 'c', ext::forward_tree < char > ( 'b' ) } ); + + std::swap ( t2.getChildren ( ).front (), t.getChildren().front ( ) ); + CHECK ( t2 == ext::forward_tree < char > ( 'c', ext::forward_tree < char > ( 'a' ) ) ); + CHECK ( t == ext::forward_tree < char > ( 'a', ext::forward_tree < char > ( 'c', ext::forward_tree < char > ( 'b' ) ), ext::forward_tree < char > ( 'b', ext::forward_tree < char > ( 'a' ), ext::forward_tree < char > ( 'b' ) ) ) ); + std::swap ( t2.getChildren ( ).front (), t.getChildren().front ( ) ); + + t2.insert ( t2.end ( ), t ); + + ext::vector < char > data = { 'd', 'e' }; + t2.insert ( t2.end ( ), data.begin ( ), data.end ( ) ); + + print_tree ( t, ""); + + t2.erase ( std::prev ( t2.end ( ) ) ); + t2.push_back ( 'f' ); + + print_tree ( t2, ""); + + CHECK( ( char ) t2 ( 1, 1 ) == 'b' ); + t2 ( 1, 1 ) = 'c'; + CHECK( ( char ) t2 ( 1, 1 ) == 'c' ); + + ext::forward_tree < char >::const_prefix_iterator beg = t2.prefix_begin ( ); + beg++; + beg++; + beg++; + beg++; + beg++; + beg++; + beg++; + beg--; + beg--; + beg--; + beg--; + beg--; + beg--; + beg--; + + CHECK ( beg == t2.prefix_begin ( ) ); + std::cout << t2 << std::endl; + std::stringstream ss; + ss << t2; + CHECK ( ss.str ( ) == "[0c[1c[2b],1a[2a,2c[3a,3b]],1d,1f]]" ); + + ext::vector < std::pair < unsigned, char > > expectedPrefix = { { 0, 'c' }, { 1, 'c' }, { 2, 'b' }, { 1, 'a' }, { 2, 'a' }, { 2, 'c' }, { 3, 'a' }, { 3, 'b' }, { 1, 'd' }, { 1, 'f' } }; + ext::vector < std::pair < unsigned, char > >::const_iterator ref = expectedPrefix.begin ( ); + + for ( ext::forward_tree < char >::const_prefix_iterator iter = t2.prefix_begin ( ); iter != t2.prefix_end ( ); ++iter ) { + CHECK ( iter.getLevel ( ) == ref->first ); + CHECK ( * iter == ref->second ); + ++iter; + --iter; + ++ref; + } + + ext::vector < ext::tuple < unsigned, char, bool > > expectedStructure = { ext::make_tuple ( 0u, 'c', false ), ext::make_tuple ( 1u, 'c', false ), ext::make_tuple ( 2u, 'b', false ), ext::make_tuple ( 2u, 'b', true ), ext::make_tuple ( 1u, 'c', true ), ext::make_tuple ( 1u, 'a', false ), ext::make_tuple ( 2u, 'a', false ), ext::make_tuple ( 2u, 'a', true ), ext::make_tuple ( 2u, 'c', false ), ext::make_tuple ( 3u, 'a', false ), ext::make_tuple ( 3u, 'a', true ), ext::make_tuple ( 3u, 'b', false ), ext::make_tuple ( 3u, 'b', true ), ext::make_tuple ( 2u, 'c', true ), ext::make_tuple ( 1u, 'a', true ), ext::make_tuple ( 1u, 'd', false ), ext::make_tuple ( 1u, 'd', true ), ext::make_tuple ( 1u, 'f', false ), ext::make_tuple ( 1u, 'f', true ), ext::make_tuple ( 0u, 'c', true ) }; + ext::vector < ext::tuple < unsigned, char, bool > >::const_iterator ref2 = expectedStructure.begin ( ); + + for ( ext::forward_tree < char >::const_structure_iterator iter = t2.structure_begin ( ); iter != t2.structure_end ( ); ++iter ) { + CHECK ( iter.getLevel ( ) == std::get < 0 > ( * ref2 ) ); + CHECK ( * iter == std::get < 1 > ( * ref2 ) ); + CHECK ( iter.getVirtual ( ) == std::get < 2 > ( * ref2 ) ); + ++iter; + --iter; + ++ref2; + } + + ext::vector < std::pair < unsigned, char > > expectedPostfix = { { 2, 'b' }, { 1, 'c' }, { 2, 'a' }, { 3, 'a' }, { 3, 'b' }, { 2, 'c' }, { 1, 'a' }, { 1, 'd' }, { 1, 'f' }, { 0, 'c' } }; + ext::vector < std::pair < unsigned, char > >::const_iterator ref3 = expectedPostfix.begin ( ); + + for ( ext::forward_tree < char >::const_postfix_iterator iter = t2.postfix_begin ( ); iter != t2.postfix_end ( ); ++iter ) { + CHECK ( iter.getLevel ( ) == ref3->first ); + CHECK ( * iter == ref3->second ); + ++iter; + --iter; + ++ref3; + } + + ext::forward_tree < char > cmp1 ( 'a' ); + ext::forward_tree < char > cmp2 ( 'b' ); + ext::forward_tree < char > cmp3 ( 'c' ); + + CHECK ( cmp1 < cmp2 ); + CHECK ( cmp2 < cmp3 ); + CHECK ( cmp2 <= cmp3 ); + CHECK ( cmp2 == cmp2 ); + CHECK ( cmp1 != cmp2 ); } - - ext::vector < ext::tuple < unsigned, char, bool > > expectedStructure = { ext::make_tuple ( 0u, 'c', false ), ext::make_tuple ( 1u, 'c', false ), ext::make_tuple ( 2u, 'b', false ), ext::make_tuple ( 2u, 'b', true ), ext::make_tuple ( 1u, 'c', true ), ext::make_tuple ( 1u, 'a', false ), ext::make_tuple ( 2u, 'a', false ), ext::make_tuple ( 2u, 'a', true ), ext::make_tuple ( 2u, 'c', false ), ext::make_tuple ( 3u, 'a', false ), ext::make_tuple ( 3u, 'a', true ), ext::make_tuple ( 3u, 'b', false ), ext::make_tuple ( 3u, 'b', true ), ext::make_tuple ( 2u, 'c', true ), ext::make_tuple ( 1u, 'a', true ), ext::make_tuple ( 1u, 'd', false ), ext::make_tuple ( 1u, 'd', true ), ext::make_tuple ( 1u, 'f', false ), ext::make_tuple ( 1u, 'f', true ), ext::make_tuple ( 0u, 'c', true ) }; - ext::vector < ext::tuple < unsigned, char, bool > >::const_iterator ref2 = expectedStructure.begin ( ); - - for ( ext::forward_tree < char >::const_structure_iterator iter = t2.structure_begin ( ); iter != t2.structure_end ( ); ++iter ) { - CPPUNIT_ASSERT ( iter.getLevel ( ) == std::get < 0 > ( * ref2 ) ); - CPPUNIT_ASSERT ( * iter == std::get < 1 > ( * ref2 ) ); - CPPUNIT_ASSERT ( iter.getVirtual ( ) == std::get < 2 > ( * ref2 ) ); - ++iter; - --iter; - ++ref2; - } - - ext::vector < std::pair < unsigned, char > > expectedPostfix = { { 2, 'b' }, { 1, 'c' }, { 2, 'a' }, { 3, 'a' }, { 3, 'b' }, { 2, 'c' }, { 1, 'a' }, { 1, 'd' }, { 1, 'f' }, { 0, 'c' } }; - ext::vector < std::pair < unsigned, char > >::const_iterator ref3 = expectedPostfix.begin ( ); - - for ( ext::forward_tree < char >::const_postfix_iterator iter = t2.postfix_begin ( ); iter != t2.postfix_end ( ); ++iter ) { - CPPUNIT_ASSERT ( iter.getLevel ( ) == ref3->first ); - CPPUNIT_ASSERT ( * iter == ref3->second ); - ++iter; - --iter; - ++ref3; - } - - ext::forward_tree < char > cmp1 ( 'a' ); - ext::forward_tree < char > cmp2 ( 'b' ); - ext::forward_tree < char > cmp3 ( 'c' ); - - CPPUNIT_ASSERT ( cmp1 < cmp2 ); - CPPUNIT_ASSERT ( cmp2 < cmp3 ); - CPPUNIT_ASSERT ( cmp2 <= cmp3 ); - CPPUNIT_ASSERT ( cmp2 == cmp2 ); - CPPUNIT_ASSERT ( cmp1 != cmp2 ); } diff --git a/alib2std/test-src/extensions/container/ForwardTreeTest.h b/alib2std/test-src/extensions/container/ForwardTreeTest.h deleted file mode 100644 index b834e26863..0000000000 --- a/alib2std/test-src/extensions/container/ForwardTreeTest.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef TREE_TEST_H_ -#define TREE_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/compare> -#include <alib/forward_tree> - -class ForwardTreeTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( ForwardTreeTest ); - CPPUNIT_TEST ( testTreeStdStructure ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - - struct RankedArityChecker { - bool operator ()( char symbol, unsigned wantedRank ) const { - switch ( symbol ) { - case 'a': - return wantedRank == 2; - - case 'b': - return wantedRank == 1; - - default: - return wantedRank == 0; - } - } - - }; - - void print_tree ( const ext::forward_tree < char > & tree, std::string indent ); - void setUp ( ); - void tearDown ( ); - - void testTreeStdStructure(); -}; - -#endif // TREE_TEST_H_ diff --git a/alib2std/test-src/extensions/container/LinearSetTest.cpp b/alib2std/test-src/extensions/container/LinearSetTest.cpp index 778fbaafea..13015b9e51 100644 --- a/alib2std/test-src/extensions/container/LinearSetTest.cpp +++ b/alib2std/test-src/extensions/container/LinearSetTest.cpp @@ -1,85 +1,107 @@ -#include "LinearSetTest.h" +#include <catch2/catch.hpp> #include <alib/linear_set> #include <alib/algorithm> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( LinearSetTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( LinearSetTest ); - -void LinearSetTest::setUp() { -} - -void LinearSetTest::tearDown() { +namespace { + class Moveable { + int& m_moves; + int& m_copies; + + public: + Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { + m_moves = 0; + m_copies = 0; + } + + Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_copies++; + } + + Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_moves++; + } + + Moveable & operator = ( Moveable && other ) { + std::swap ( m_moves, other.m_moves ); + std::swap ( m_copies, other.m_copies ); + return *this; + } + + bool operator<(const Moveable&) const { + return false; + } + }; } - -void LinearSetTest::test1() { - ext::vector < int > data = { 1, 4, 3 }; - ext::linear_set < int > test_set_1; - ext::linear_set < int > test_set_2 ( data.begin ( ), data.end ( ) ); - - CPPUNIT_ASSERT ( test_set_1.size ( ) == 0 ); - CPPUNIT_ASSERT ( test_set_1.empty ( ) ); - CPPUNIT_ASSERT ( test_set_2.size ( ) == 3 ); - - test_set_1.insert ( 1 ); - CPPUNIT_ASSERT ( test_set_1.size ( ) == 1 ); - CPPUNIT_ASSERT ( ! test_set_1.empty ( ) ); - for ( int elem : test_set_1 ) { - CPPUNIT_ASSERT ( elem == 1 ); +TEST_CASE ( "LinearSet", "[unit][std][container]" ) { + SECTION ( "Test1" ) { + ext::vector < int > data = { 1, 4, 3 }; + ext::linear_set < int > test_set_1; + ext::linear_set < int > test_set_2 ( data.begin ( ), data.end ( ) ); + + CHECK ( test_set_1.size ( ) == 0 ); + CHECK ( test_set_1.empty ( ) ); + CHECK ( test_set_2.size ( ) == 3 ); + + test_set_1.insert ( 1 ); + CHECK ( test_set_1.size ( ) == 1 ); + CHECK ( ! test_set_1.empty ( ) ); + for ( int elem : test_set_1 ) { + CHECK ( elem == 1 ); + } + test_set_1.clear ( ); + CHECK ( test_set_1.empty ( ) ); + ext::linear_set < int >::iterator iter = test_set_1.insert ( data [0] ).first; + CHECK ( iter == test_set_1.begin ( ) ); + + iter = test_set_1.insert ( data [1] ).first; + CHECK ( iter == test_set_1.begin ( ) + 1 ); + + iter = test_set_1.insert ( data [2] ).first; + CHECK ( iter == test_set_1.begin ( ) + 1 ); + + CHECK ( test_set_1 == test_set_2 ); + CHECK ( ! test_set_1.insert ( data [0] ).second ); + iter = test_set_1.insert ( data [0] ).first; + CHECK ( iter == test_set_1.begin ( ) ); + + test_set_1.insert ( { 2, 3 } ); + CHECK ( test_set_1.size ( ) == 4 ); + + ext::vector < int > ref = { 1, 2, 3, 4 }; + ext::vector < int > copy ( test_set_1.begin ( ), test_set_1.end ( ) ); + CHECK ( ref == copy ); + + ref = { 4, 3, 2, 1 }; + copy = ext::vector < int > ( test_set_1.rbegin ( ), test_set_1.rend ( ) ); + CHECK ( ref == copy ); } - test_set_1.clear ( ); - CPPUNIT_ASSERT ( test_set_1.empty ( ) ); - ext::linear_set < int >::iterator iter = test_set_1.insert ( data [0] ).first; - CPPUNIT_ASSERT ( iter == test_set_1.begin ( ) ); - - iter = test_set_1.insert ( data [1] ).first; - CPPUNIT_ASSERT ( iter == test_set_1.begin ( ) + 1 ); - - iter = test_set_1.insert ( data [2] ).first; - CPPUNIT_ASSERT ( iter == test_set_1.begin ( ) + 1 ); - CPPUNIT_ASSERT ( test_set_1 == test_set_2 ); - CPPUNIT_ASSERT ( ! test_set_1.insert ( data [0] ).second ); - iter = test_set_1.insert ( data [0] ).first; - CPPUNIT_ASSERT ( iter == test_set_1.begin ( ) ); + SECTION ( "Test2" ) { + ext::linear_set<int> first = {1}; + ext::linear_set<int> second = {1, 2, 3}; - test_set_1.insert ( { 2, 3 } ); - CPPUNIT_ASSERT ( test_set_1.size ( ) == 4 ); + ext::linear_set<int> firstMinusSecond; + ext::linear_set<int> secondMinusFirst; - ext::vector < int > ref = { 1, 2, 3, 4 }; - ext::vector < int > copy ( test_set_1.begin ( ), test_set_1.end ( ) ); - CPPUNIT_ASSERT ( ref == copy ); + std::set_difference (first.begin(), first.end(), second.begin(), second.end(), std::inserter(firstMinusSecond, firstMinusSecond.end())); + std::set_difference (second.begin(), second.end(), first.begin(), first.end(), std::inserter(secondMinusFirst, secondMinusFirst.end())); - ref = { 4, 3, 2, 1 }; - copy = ext::vector < int > ( test_set_1.rbegin ( ), test_set_1.rend ( ) ); - CPPUNIT_ASSERT ( ref == copy ); -} - -void LinearSetTest::test2() { - ext::linear_set<int> first = {1}; - ext::linear_set<int> second = {1, 2, 3}; - - ext::linear_set<int> firstMinusSecond; - ext::linear_set<int> secondMinusFirst; - - std::set_difference (first.begin(), first.end(), second.begin(), second.end(), std::inserter(firstMinusSecond, firstMinusSecond.end())); - std::set_difference (second.begin(), second.end(), first.begin(), first.end(), std::inserter(secondMinusFirst, secondMinusFirst.end())); + CHECK(firstMinusSecond.size() == (size_t) 0u); + CHECK(secondMinusFirst.size() == (size_t) 2u); + } - CPPUNIT_ASSERT_EQUAL(firstMinusSecond.size(), (size_t) 0u); - CPPUNIT_ASSERT_EQUAL(secondMinusFirst.size(), (size_t) 2u); -} + SECTION ( "Test3" ) { + int moves; + int copies; -void LinearSetTest::test3() { - int moves; - int copies; + ext::linear_set<Moveable> set; + set.insert ( Moveable(moves, copies) ); + ext::linear_set<Moveable> set2; - ext::linear_set<LinearSetTest::Moveable> set; - set.insert ( LinearSetTest::Moveable(moves, copies) ); - ext::linear_set<LinearSetTest::Moveable> set2; + for(Moveable moveable : ext::make_mover ( set ) ) { + set2.insert(std::move(moveable)); + } - for(Moveable moveable : ext::make_mover ( set ) ) { - set2.insert(std::move(moveable)); + CHECK(copies == 0); } - - CPPUNIT_ASSERT(copies == 0); } - diff --git a/alib2std/test-src/extensions/container/LinearSetTest.h b/alib2std/test-src/extensions/container/LinearSetTest.h deleted file mode 100644 index 18474c1e02..0000000000 --- a/alib2std/test-src/extensions/container/LinearSetTest.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef SET_TEST_H_ -#define SET_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class LinearSetTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( LinearSetTest ); - CPPUNIT_TEST( test1 ); - CPPUNIT_TEST( test2 ); - CPPUNIT_TEST( test3 ); - CPPUNIT_TEST_SUITE_END(); - -public: -class Moveable { - int& m_moves; - int& m_copies; - -public: - Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { - m_moves = 0; - m_copies = 0; - } - - Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_copies++; - } - - Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_moves++; - } - - Moveable & operator = ( Moveable && other ) { - std::swap ( m_moves, other.m_moves ); - std::swap ( m_copies, other.m_copies ); - return *this; - } - - bool operator<(const Moveable&) const { - return false; - } -}; - -public: - void setUp(); - void tearDown(); - - void test1(); - void test2(); - void test3(); -}; - -#endif // SET_TEST_H_ diff --git a/alib2std/test-src/extensions/container/MapTest.cpp b/alib2std/test-src/extensions/container/MapTest.cpp index ec9bd03976..d61eca037e 100644 --- a/alib2std/test-src/extensions/container/MapTest.cpp +++ b/alib2std/test-src/extensions/container/MapTest.cpp @@ -1,32 +1,58 @@ -#include "MapTest.h" +#include <catch2/catch.hpp> #include <alib/map> #include <alib/algorithm> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( MapTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( MapTest ); - -void MapTest::setUp() { -} - -void MapTest::tearDown() { +namespace { + class Moveable { + int& m_moves; + int& m_copies; + + public: + Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { + m_moves = 0; + m_copies = 0; + } + + Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_copies++; + } + + Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_moves++; + } + + Moveable & operator = ( const Moveable & ) { + m_copies ++; + return * this; + } + + Moveable & operator = ( Moveable && ) { + m_moves ++; + return * this; + } + + bool operator<(const Moveable&) const { + return false; + } + }; } +TEST_CASE ( "Map", "[unit][std][container]" ) { + SECTION ( "Basic" ) { + int moves; + int copies; -void MapTest::test3() { - int moves; - int copies; + ext::map<Moveable, Moveable> map; + map.insert ( Moveable(moves, copies ), Moveable(moves, copies) ); + ext::map<Moveable, Moveable> map2; - ext::map<MapTest::Moveable, MapTest::Moveable> map; - map.insert ( MapTest::Moveable(moves, copies ), MapTest::Moveable(moves, copies) ); - ext::map<MapTest::Moveable, MapTest::Moveable> map2; + for( std::pair < Moveable, Moveable > moveablePair : ext::make_mover ( map ) ) { + map2.insert(std::move(moveablePair)); + } - for( std::pair < Moveable, Moveable > moveablePair : ext::make_mover ( map ) ) { - map2.insert(std::move(moveablePair)); - } + bool res = map2.insert_or_assign ( Moveable ( moves, copies ), Moveable ( moves, copies ) ).second; - bool res = map2.insert_or_assign ( MapTest::Moveable ( moves, copies ), MapTest::Moveable ( moves, copies ) ).second; + CHECK ( res == false ); - CPPUNIT_ASSERT ( res == false ); - - CPPUNIT_ASSERT(copies == 0); + CHECK ( copies == 0 ); + } } - diff --git a/alib2std/test-src/extensions/container/MapTest.h b/alib2std/test-src/extensions/container/MapTest.h deleted file mode 100644 index a43132aecc..0000000000 --- a/alib2std/test-src/extensions/container/MapTest.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef MAP_TEST_H_ -#define MAP_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class MapTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( MapTest ); - CPPUNIT_TEST( test3 ); - CPPUNIT_TEST_SUITE_END(); - -public: -class Moveable { - int& m_moves; - int& m_copies; - -public: - Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { - m_moves = 0; - m_copies = 0; - } - - Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_copies++; - } - - Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_moves++; - } - - Moveable & operator = ( const Moveable & ) { - m_copies ++; - return * this; - } - - Moveable & operator = ( Moveable && ) { - m_moves ++; - return * this; - } - - bool operator<(const Moveable&) const { - return false; - } -}; - -public: - void setUp(); - void tearDown(); - - void test3(); -}; - -#endif // MAP_TEST_H_ diff --git a/alib2std/test-src/extensions/container/PtrArrayTest.cpp b/alib2std/test-src/extensions/container/PtrArrayTest.cpp index 120cede233..6d292a9ac3 100644 --- a/alib2std/test-src/extensions/container/PtrArrayTest.cpp +++ b/alib2std/test-src/extensions/container/PtrArrayTest.cpp @@ -1,43 +1,83 @@ -#include "PtrArrayTest.h" +#include <catch2/catch.hpp> #include <alib/ptr_array> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PtrArrayTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( PtrArrayTest ); +namespace { + enum class Type { + CHILD1, + CHILD2 + }; -void PtrArrayTest::setUp() { -} + class Base { + public: + virtual ~Base ( ) { + } -void PtrArrayTest::tearDown() { -} + virtual Base * clone ( ) const & = 0; + virtual Base * clone ( ) && = 0; + + virtual Type type ( ) const = 0; + }; + + class Child1 : public Base { + public: + virtual Base * clone ( ) const & { + return new Child1 ( * this ); + } + + virtual Base * clone ( ) && { + return new Child1 ( * this ); + } + + virtual Type type ( ) const { + return Type::CHILD1; + } + }; -void PtrArrayTest::testProperties() { - ext::ptr_array < int, 4 > data = {1, 2, 3, 4}; + class Child2 : public Base { + public: + virtual Base * clone ( ) const & { + return new Child2 ( * this ); + } - std::cout << data [ 0 ] << std::endl; + virtual Base * clone ( ) && { + return new Child2 ( * this ); + } - CPPUNIT_ASSERT ( data [ 0 ] == 1 ); - CPPUNIT_ASSERT ( data.size ( ) == 4 ); - CPPUNIT_ASSERT ( data [ 3 ] == 4 ); + virtual Type type ( ) const { + return Type::CHILD2; + } + }; } +TEST_CASE ( "PtrArray", "[unit][std][container]" ) { + SECTION ( "Test Properties" ) { + ext::ptr_array < int, 4 > data = {1, 2, 3, 4}; + + CAPTURE ( data [ 0 ], data.size ( ), data [ 3 ] ); + + CHECK ( data [ 0 ] == 1 ); + CHECK ( data.size ( ) == 4 ); + CHECK ( data [ 3 ] == 4 ); + } + + + SECTION ( "Test polymorphism" ) { + ext::ptr_array < Base, 4 > data = ext::make_ptr_array < Base > ( Child1 ( ), Child1 ( ), Child2 ( ), Child2 ( ) ); + + REQUIRE ( data.size ( ) == 4 ); -void PtrArrayTest::testPolymorph() { - ext::ptr_array < Base, 4 > data = ext::make_ptr_array < Base > ( Child1 ( ), Child1 ( ), Child2 ( ), Child2 ( ) ); - - CPPUNIT_ASSERT ( data.size ( ) == 4 ); - - CPPUNIT_ASSERT ( data [ 0 ].type ( ) == PtrArrayTest::Type::CHILD1 ); - CPPUNIT_ASSERT ( data [ 1 ].type ( ) == PtrArrayTest::Type::CHILD1 ); - CPPUNIT_ASSERT ( data [ 2 ].type ( ) == PtrArrayTest::Type::CHILD2 ); - CPPUNIT_ASSERT ( data [ 3 ].type ( ) == PtrArrayTest::Type::CHILD2 ); - - ext::ptr_array < Base, 4 >::const_iterator iter = data.cbegin ( ); - CPPUNIT_ASSERT ( iter->type ( ) == PtrArrayTest::Type::CHILD1 ); - ++ iter; - CPPUNIT_ASSERT ( iter->type ( ) == PtrArrayTest::Type::CHILD1 ); - ++ iter; - CPPUNIT_ASSERT ( iter->type ( ) == PtrArrayTest::Type::CHILD2 ); - ++ iter; - CPPUNIT_ASSERT ( iter->type ( ) == PtrArrayTest::Type::CHILD2 ); - ++ iter; - CPPUNIT_ASSERT ( iter == data.cend ( ) ); + CHECK ( data [ 0 ].type ( ) == Type::CHILD1 ); + CHECK ( data [ 1 ].type ( ) == Type::CHILD1 ); + CHECK ( data [ 2 ].type ( ) == Type::CHILD2 ); + CHECK ( data [ 3 ].type ( ) == Type::CHILD2 ); + ext::ptr_array < Base, 4 >::const_iterator iter = data.cbegin ( ); + CHECK ( iter->type ( ) == Type::CHILD1 ); + ++ iter; + CHECK ( iter->type ( ) == Type::CHILD1 ); + ++ iter; + CHECK ( iter->type ( ) == Type::CHILD2 ); + ++ iter; + CHECK ( iter->type ( ) == Type::CHILD2 ); + ++ iter; + CHECK ( iter == data.cend ( ) ); + } } diff --git a/alib2std/test-src/extensions/container/PtrArrayTest.h b/alib2std/test-src/extensions/container/PtrArrayTest.h deleted file mode 100644 index 0b6e330810..0000000000 --- a/alib2std/test-src/extensions/container/PtrArrayTest.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef PTR_ARRAY_TEST_H_ -#define PTR_ARRAY_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/compare> - -class PtrArrayTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( PtrArrayTest ); - CPPUNIT_TEST( testProperties ); - CPPUNIT_TEST( testPolymorph ); - CPPUNIT_TEST_SUITE_END(); - - enum class Type { - CHILD1, - CHILD2 - }; - - class Base { - public: - virtual ~Base ( ) { - } - - virtual Base * clone ( ) const = 0; - virtual Base * plunder ( ) && = 0; - - virtual Type type ( ) const = 0; - }; - - class Child1 : public Base { - public: - virtual Base * clone ( ) const { - return new Child1 ( * this ); - } - - virtual Base * plunder ( ) && { - return new Child1 ( * this ); - } - - virtual Type type ( ) const { - return Type::CHILD1; - } - }; - - class Child2 : public Base { - public: - virtual Base * clone ( ) const { - return new Child2 ( * this ); - } - - virtual Base * plunder ( ) && { - return new Child2 ( * this ); - } - - virtual Type type ( ) const { - return Type::CHILD2; - } - }; - -public: - void setUp(); - void tearDown(); - - void testProperties(); - void testPolymorph(); -}; - -#endif // PTR_ARRAY_TEST_H_ diff --git a/alib2std/test-src/extensions/container/PtrTupleTest.cpp b/alib2std/test-src/extensions/container/PtrTupleTest.cpp index 3b1e6ffd8e..5c45a69faa 100644 --- a/alib2std/test-src/extensions/container/PtrTupleTest.cpp +++ b/alib2std/test-src/extensions/container/PtrTupleTest.cpp @@ -1,26 +1,18 @@ -#include "PtrTupleTest.h" +#include <catch2/catch.hpp> #include <alib/ptr_tuple> #include <sstream> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PtrTupleTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( PtrTupleTest ); +TEST_CASE ( "PtrTuple", "[unit][std][container]" ) { + SECTION ( "Test call on nth" ) { + ext::ptr_tuple < int, int, int, int, int > t = ext::make_ptr_tuple ( 1, 2, 3, 4, 5 ); -void PtrTupleTest::setUp() { -} - -void PtrTupleTest::tearDown() { -} + CHECK ( ext::call_on_nth < int > ( t, 1, [] ( int i ) { return i; } ) == 2 ); -void PtrTupleTest::testCallOnNth() { - ext::ptr_tuple < int, int, int, int, int > t = ext::make_ptr_tuple ( 1, 2, 3, 4, 5 ); + std::stringstream ss; + ss << t; + CAPTURE ( ss.str ( ) ); + CHECK ( ss.str ( ) == "(1, 2, 3, 4, 5)" ); - CPPUNIT_ASSERT ( ext::call_on_nth < int > ( t, 1, [] ( int i ) { return i; } ) == 2 ); - - std::stringstream ss; - ss << t; - std::cout << ss.str ( ) << std::endl; - CPPUNIT_ASSERT ( ss.str ( ) == "(1, 2, 3, 4, 5)" ); - - CPPUNIT_ASSERT ( t == t ); + CHECK ( t == t ); + } } - diff --git a/alib2std/test-src/extensions/container/PtrTupleTest.h b/alib2std/test-src/extensions/container/PtrTupleTest.h deleted file mode 100644 index 9092c32436..0000000000 --- a/alib2std/test-src/extensions/container/PtrTupleTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef PTR_TUPLE_TEST_H_ -#define PTR_TUPLE_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class PtrTupleTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( PtrTupleTest ); - CPPUNIT_TEST( testCallOnNth ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testCallOnNth(); -}; - -#endif // PTR_TUPLE_TEST_H_ diff --git a/alib2std/test-src/extensions/container/PtrVectorTest.cpp b/alib2std/test-src/extensions/container/PtrVectorTest.cpp index 9a164e4555..1c3a0bfcd3 100644 --- a/alib2std/test-src/extensions/container/PtrVectorTest.cpp +++ b/alib2std/test-src/extensions/container/PtrVectorTest.cpp @@ -1,99 +1,176 @@ -#include "PtrVectorTest.h" +#include <catch2/catch.hpp> #include <alib/ptr_vector> #include <alib/algorithm> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( PtrVectorTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( PtrVectorTest ); - -void PtrVectorTest::setUp() { -} - -void PtrVectorTest::tearDown() { +namespace { + enum class Type { + CHILD1, + CHILD2 + }; + + class Base { + public: + virtual ~Base ( ) { + } + + virtual Base * clone ( ) const = 0; + virtual Base * plunder ( ) && = 0; + + virtual Type type ( ) const = 0; + + bool operator == ( const Base & other ) const { + return this->type ( ) == other.type ( ); + } + + }; + + class Child1 : public Base { + public: + virtual Base * clone ( ) const { + return new Child1 ( * this ); + } + + virtual Base * plunder ( ) && { + return new Child1 ( * this ); + } + + virtual Type type ( ) const { + return Type::CHILD1; + } + }; + + class Child2 : public Base { + public: + virtual Base * clone ( ) const { + return new Child2 ( * this ); + } + + virtual Base * plunder ( ) && { + return new Child2 ( * this ); + } + + virtual Type type ( ) const { + return Type::CHILD2; + } + }; + + class Moveable { + int& m_moves; + int& m_copies; + + public: + Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { + m_moves = 0; + m_copies = 0; + } + + Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_copies++; + } + + Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_moves++; + } + + Moveable & operator = ( const Moveable & ) { + m_copies ++; + return * this; + } + + Moveable & operator = ( Moveable && ) { + m_moves ++; + return * this; + } + + bool operator<(const Moveable&) const { + return false; + } + }; } -void PtrVectorTest::testProperties() { - ext::ptr_vector < int > data = {1, 2, 3, 4}; +TEST_CASE ( "PtrVector", "[unit][std][container]" ) { + SECTION ( "Test Properties" ) { + ext::ptr_vector < int > data = {1, 2, 3, 4}; - std::cout << data [ 0 ] << std::endl; + CHECK ( data [ 0 ] == 1 ); + CHECK ( data.size ( ) == 4 ); + CHECK ( data [ 3 ] == 4 ); - CPPUNIT_ASSERT ( data [ 0 ] == 1 ); - CPPUNIT_ASSERT ( data.size ( ) == 4 ); - CPPUNIT_ASSERT ( data [ 3 ] == 4 ); + data.push_back ( 1 ); + CHECK ( data.size ( ) == 5 ); + CHECK ( data [ 4 ] == 1 ); - data.push_back ( 1 ); - CPPUNIT_ASSERT ( data.size ( ) == 5 ); - CPPUNIT_ASSERT ( data [ 4 ] == 1 ); + data.insert ( data.cbegin ( ) + 1, 2 ); + CHECK ( data.size ( ) == 6 ); + CHECK ( data [ 1 ] == 2 ); + CHECK ( data [ 2 ] == 2 ); + CHECK ( data [ 3 ] == 3 ); + } - data.insert ( data.cbegin ( ) + 1, 2 ); - CPPUNIT_ASSERT ( data.size ( ) == 6 ); - CPPUNIT_ASSERT ( data [ 1 ] == 2 ); - CPPUNIT_ASSERT ( data [ 2 ] == 2 ); - CPPUNIT_ASSERT ( data [ 3 ] == 3 ); -} - -void PtrVectorTest::testPolymorph() { - ext::ptr_vector < Base > data = { Child2 ( ) }; + SECTION ( "Test Polymorphism" ) { + ext::ptr_vector < Base > data = { Child2 ( ) }; - CPPUNIT_ASSERT ( data [ 0 ].type ( ) == PtrVectorTest::Type::CHILD2 ); - CPPUNIT_ASSERT ( data.size ( ) == 1 ); + CHECK ( data [ 0 ].type ( ) == Type::CHILD2 ); + CHECK ( data.size ( ) == 1 ); - data.push_back ( Child1 ( ) ); - CPPUNIT_ASSERT ( data.size ( ) == 2 ); - CPPUNIT_ASSERT ( data [ 1 ].type ( ) == PtrVectorTest::Type::CHILD1 ); + data.push_back ( Child1 ( ) ); + CHECK ( data.size ( ) == 2 ); + CHECK ( data [ 1 ].type ( ) == Type::CHILD1 ); - ext::ptr_vector < Base >::const_iterator iter = data.cbegin ( ); - CPPUNIT_ASSERT ( iter->type ( ) == PtrVectorTest::Type::CHILD2 ); - ++ iter; - CPPUNIT_ASSERT ( iter->type ( ) == PtrVectorTest::Type::CHILD1 ); - ++ iter; - CPPUNIT_ASSERT ( iter == data.cend ( ) ); + ext::ptr_vector < Base >::const_iterator iter = data.cbegin ( ); + CHECK ( iter->type ( ) == Type::CHILD2 ); + ++ iter; + CHECK ( iter->type ( ) == Type::CHILD1 ); + ++ iter; + CHECK ( iter == data.cend ( ) ); - data.insert ( data.cbegin ( ) + 1, Child1 ( ) ); - CPPUNIT_ASSERT ( data.size ( ) == 3 ); - CPPUNIT_ASSERT ( data [ 0 ].type ( ) == PtrVectorTest::Type::CHILD2 ); - CPPUNIT_ASSERT ( data [ 1 ].type ( ) == PtrVectorTest::Type::CHILD1 ); - CPPUNIT_ASSERT ( data [ 2 ].type ( ) == PtrVectorTest::Type::CHILD1 ); + data.insert ( data.cbegin ( ) + 1, Child1 ( ) ); + CHECK ( data.size ( ) == 3 ); + CHECK ( data [ 0 ].type ( ) == Type::CHILD2 ); + CHECK ( data [ 1 ].type ( ) == Type::CHILD1 ); + CHECK ( data [ 2 ].type ( ) == Type::CHILD1 ); - data.resize < Child2 > ( 4 ); - CPPUNIT_ASSERT ( data.at ( 3 ) == Child2 ( ) ); - data.shrink ( 3 ); + data.resize < Child2 > ( 4 ); + CHECK ( data.at ( 3 ) == Child2 ( ) ); + data.shrink ( 3 ); - ext::ptr_vector < Base > data2 = data; + ext::ptr_vector < Base > data2 = data; - CPPUNIT_ASSERT ( data2 [ 0 ].type ( ) == PtrVectorTest::Type::CHILD2 ); - CPPUNIT_ASSERT ( data2 [ 1 ].type ( ) == PtrVectorTest::Type::CHILD1 ); - CPPUNIT_ASSERT ( data2 [ 2 ].type ( ) == PtrVectorTest::Type::CHILD1 ); + CHECK ( data2 [ 0 ].type ( ) == Type::CHILD2 ); + CHECK ( data2 [ 1 ].type ( ) == Type::CHILD1 ); + CHECK ( data2 [ 2 ].type ( ) == Type::CHILD1 ); - auto iter2 = data2.insert ( data2.cbegin ( ) + 1, data.begin ( ), data.end ( ) ); + auto iter2 = data2.insert ( data2.cbegin ( ) + 1, data.begin ( ), data.end ( ) ); - CPPUNIT_ASSERT ( iter2 == data2.begin ( ) + 1 ); + CHECK ( iter2 == data2.begin ( ) + 1 ); - CPPUNIT_ASSERT ( data2 [ 0 ].type ( ) == PtrVectorTest::Type::CHILD2 ); - CPPUNIT_ASSERT ( data2 [ 1 ].type ( ) == PtrVectorTest::Type::CHILD2 ); - CPPUNIT_ASSERT ( data2 [ 2 ].type ( ) == PtrVectorTest::Type::CHILD1 ); - CPPUNIT_ASSERT ( data2 [ 3 ].type ( ) == PtrVectorTest::Type::CHILD1 ); - CPPUNIT_ASSERT ( data2 [ 4 ].type ( ) == PtrVectorTest::Type::CHILD1 ); - CPPUNIT_ASSERT ( data2 [ 5 ].type ( ) == PtrVectorTest::Type::CHILD1 ); + CHECK ( data2 [ 0 ].type ( ) == Type::CHILD2 ); + CHECK ( data2 [ 1 ].type ( ) == Type::CHILD2 ); + CHECK ( data2 [ 2 ].type ( ) == Type::CHILD1 ); + CHECK ( data2 [ 3 ].type ( ) == Type::CHILD1 ); + CHECK ( data2 [ 4 ].type ( ) == Type::CHILD1 ); + CHECK ( data2 [ 5 ].type ( ) == Type::CHILD1 ); - data2.erase ( ext::dereferencer ( ext::unique ( data2.begin ( ).base ( ), data2.end ( ).base ( ), [ ] ( const Base * a, const Base * b ) { return * a == * b; } ) ), data2.end ( ) ); -} + data2.erase ( ext::dereferencer ( ext::unique ( data2.begin ( ).base ( ), data2.end ( ).base ( ), [ ] ( const Base * a, const Base * b ) { return * a == * b; } ) ), data2.end ( ) ); + } -void PtrVectorTest::testRange ( ) { - ext::ptr_vector < int > data { 1, 2, 3, 4 }; - ext::ptr_vector < int > data2 ( data.range ( ) ); + SECTION ( "Test Range" ) { + ext::ptr_vector < int > data { 1, 2, 3, 4 }; + ext::ptr_vector < int > data2 ( data.range ( ) ); - CPPUNIT_ASSERT ( data == data2 ); + CHECK ( data == data2 ); - int moves; - int copies; + int moves; + int copies; - ext::ptr_vector < Moveable > vec; - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); + ext::ptr_vector < Moveable > vec; + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); - ext::ptr_vector < Moveable > vec2 ( ext::range ( std::move ( vec ) ) ); + ext::ptr_vector < Moveable > vec2 ( ext::range ( std::move ( vec ) ) ); - CPPUNIT_ASSERT ( copies == 0 ); + CHECK ( copies == 0 ); + } } diff --git a/alib2std/test-src/extensions/container/PtrVectorTest.h b/alib2std/test-src/extensions/container/PtrVectorTest.h deleted file mode 100644 index 8200be689b..0000000000 --- a/alib2std/test-src/extensions/container/PtrVectorTest.h +++ /dev/null @@ -1,108 +0,0 @@ -#ifndef PTR_VECTOR_TEST_H_ -#define PTR_VECTOR_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/compare> - -class PtrVectorTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( PtrVectorTest ); - CPPUNIT_TEST( testProperties ); - CPPUNIT_TEST( testPolymorph ); - CPPUNIT_TEST( testRange ); - CPPUNIT_TEST_SUITE_END(); - - enum class Type { - CHILD1, - CHILD2 - }; - - class Base { - public: - virtual ~Base ( ) { - } - - virtual Base * clone ( ) const = 0; - virtual Base * plunder ( ) && = 0; - - virtual Type type ( ) const = 0; - - bool operator == ( const PtrVectorTest::Base & other ) const { - return this->type ( ) == other.type ( ); - } - - }; - - class Child1 : public Base { - public: - virtual Base * clone ( ) const { - return new Child1 ( * this ); - } - - virtual Base * plunder ( ) && { - return new Child1 ( * this ); - } - - virtual Type type ( ) const { - return Type::CHILD1; - } - }; - - class Child2 : public Base { - public: - virtual Base * clone ( ) const { - return new Child2 ( * this ); - } - - virtual Base * plunder ( ) && { - return new Child2 ( * this ); - } - - virtual Type type ( ) const { - return Type::CHILD2; - } - }; - -class Moveable { - int& m_moves; - int& m_copies; - -public: - Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { - m_moves = 0; - m_copies = 0; - } - - Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_copies++; - } - - Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_moves++; - } - - Moveable & operator = ( const Moveable & ) { - m_copies ++; - return * this; - } - - Moveable & operator = ( Moveable && ) { - m_moves ++; - return * this; - } - - bool operator<(const Moveable&) const { - return false; - } -}; - -public: - void setUp(); - void tearDown(); - - void testProperties(); - void testPolymorph(); - void testRange(); -}; - -#endif // PTR_VECTOR_TEST_H_ diff --git a/alib2std/test-src/extensions/container/SetTest.cpp b/alib2std/test-src/extensions/container/SetTest.cpp index e50288f14f..255cfc77fc 100644 --- a/alib2std/test-src/extensions/container/SetTest.cpp +++ b/alib2std/test-src/extensions/container/SetTest.cpp @@ -1,77 +1,96 @@ -#include "SetTest.h" +#include <catch2/catch.hpp> #include <alib/set> #include <alib/algorithm> #include <alib/vector> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( SetTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( SetTest ); - -void SetTest::setUp() { -} - -void SetTest::tearDown() { -} - -void SetTest::test1() { - int first[] = {5,10,15,20,25}; - int second[] = {50,40,30,20,10}; - ext::vector<int> v(10); // 0 0 0 0 0 0 0 0 0 0 - ext::vector<int>::iterator it; - - std::sort (first,first+5); // 5 10 15 20 25 - std::sort (second,second+5); // 10 20 30 40 50 - - it=std::set_difference (first, first+5, second, second+5, v.begin()); - v.resize(it-v.begin()); - - CPPUNIT_ASSERT_EQUAL(5, v[0]); - CPPUNIT_ASSERT_EQUAL(15, v[1]); - CPPUNIT_ASSERT_EQUAL(25, v[2]); +namespace { + class Moveable { + int& m_moves; + int& m_copies; + + public: + Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { + m_moves = 0; + m_copies = 0; + } + + Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_copies++; + } + + Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_moves++; + } + + bool operator<(const Moveable&) const { + return false; + } + }; + + static ext::set<Moveable> makeSet ( int & moves, int & copies ) { + ext::set<Moveable> set; + set.insert ( Moveable(moves, copies) ); + return set; + } } +TEST_CASE ( "Set", "[unit][std][container]" ) { + SECTION ( "Set difference" ) { + { + int first[] = {5,10,15,20,25}; + int second[] = {50,40,30,20,10}; + ext::vector<int> v(10); // 0 0 0 0 0 0 0 0 0 0 + ext::vector<int>::iterator it; + + std::sort (first,first+5); // 5 10 15 20 25 + std::sort (second,second+5); // 10 20 30 40 50 + + it=std::set_difference (first, first+5, second, second+5, v.begin()); + v.resize(it-v.begin()); + + CHECK(5 == v[0]); + CHECK(15 == v[1]); + CHECK(25 == v[2]); + } + { + ext::set<int> first = {1}; + ext::set<int> second = {1, 2, 3}; + + ext::set<int> firstMinusSecond; + ext::set<int> secondMinusFirst; + + std::set_difference (first.begin(), first.end(), second.begin(), second.end(), std::inserter(firstMinusSecond, firstMinusSecond.end())); + std::set_difference (second.begin(), second.end(), first.begin(), first.end(), std::inserter(secondMinusFirst, secondMinusFirst.end())); + + CHECK(firstMinusSecond.size() == (size_t) 0u); + CHECK(secondMinusFirst.size() == (size_t) 2u); + } + } -void SetTest::test2() { - ext::set<int> first = {1}; - ext::set<int> second = {1, 2, 3}; - - ext::set<int> firstMinusSecond; - ext::set<int> secondMinusFirst; + SECTION ( "Move" ) { + { + int moves; + int copies; - std::set_difference (first.begin(), first.end(), second.begin(), second.end(), std::inserter(firstMinusSecond, firstMinusSecond.end())); - std::set_difference (second.begin(), second.end(), first.begin(), first.end(), std::inserter(secondMinusFirst, secondMinusFirst.end())); + ext::set<Moveable> set2; - CPPUNIT_ASSERT_EQUAL(firstMinusSecond.size(), (size_t) 0u); - CPPUNIT_ASSERT_EQUAL(secondMinusFirst.size(), (size_t) 2u); -} + for(Moveable moveable : ext::make_mover ( makeSet ( moves, copies ) ) ) { + set2.insert(std::move(moveable)); + } -ext::set<SetTest::Moveable> makeSet ( int & moves, int & copies ) { - ext::set<SetTest::Moveable> set; - set.insert ( SetTest::Moveable(moves, copies) ); - return set; -} + CHECK(copies == 0); + } + { + int moves; + int copies; -void SetTest::test3() { - int moves; - int copies; + ext::set<Moveable> set; + set.insert ( Moveable(moves, copies) ); + ext::set<Moveable> set2; - ext::set<SetTest::Moveable> set2; + set2.insert ( ext::make_mover ( set ).begin ( ), ext::make_mover ( set ).end ( ) ); - for(Moveable moveable : ext::make_mover ( makeSet ( moves, copies ) ) ) { - set2.insert(std::move(moveable)); + CHECK(copies == 0); + } } - - CPPUNIT_ASSERT(copies == 0); -} - -void SetTest::test4() { - int moves; - int copies; - - ext::set<SetTest::Moveable> set; - set.insert ( SetTest::Moveable(moves, copies) ); - ext::set<SetTest::Moveable> set2; - - set2.insert ( ext::make_mover ( set ).begin ( ), ext::make_mover ( set ).end ( ) ); - - CPPUNIT_ASSERT(copies == 0); } diff --git a/alib2std/test-src/extensions/container/SetTest.h b/alib2std/test-src/extensions/container/SetTest.h deleted file mode 100644 index 9de1f1f8b0..0000000000 --- a/alib2std/test-src/extensions/container/SetTest.h +++ /dev/null @@ -1,49 +0,0 @@ -#ifndef SET_TEST_H_ -#define SET_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class SetTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( SetTest ); - CPPUNIT_TEST( test1 ); - CPPUNIT_TEST( test2 ); - CPPUNIT_TEST( test3 ); - CPPUNIT_TEST( test4 ); - CPPUNIT_TEST_SUITE_END(); - -public: -class Moveable { - int& m_moves; - int& m_copies; - -public: - Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { - m_moves = 0; - m_copies = 0; - } - - Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_copies++; - } - - Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_moves++; - } - - bool operator<(const Moveable&) const { - return false; - } -}; - -public: - void setUp(); - void tearDown(); - - void test1(); - void test2(); - void test3(); - void test4(); -}; - -#endif // SET_TEST_H_ diff --git a/alib2std/test-src/extensions/container/StringTest.cpp b/alib2std/test-src/extensions/container/StringTest.cpp index 50c107fe1c..24e9f19e98 100644 --- a/alib2std/test-src/extensions/container/StringTest.cpp +++ b/alib2std/test-src/extensions/container/StringTest.cpp @@ -1,69 +1,71 @@ -#include "StringTest.h" +#include <catch2/catch.hpp> #include <alib/string> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( StringTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( StringTest ); - -void StringTest::setUp() { +namespace { + class A { + public: + explicit operator std::string ( ) const { + return ""; + } + }; } -void StringTest::tearDown() { -} +TEST_CASE ( "String", "[unit][std][container]" ) { + SECTION ( "ToString" ) { + CHECK ( ext::to_string ( std::string ( "1" ) ) == "1" ); + CHECK ( ext::to_string ( 1 ) == "1" ); + CHECK ( ext::to_string ( 1ul ) == "1" ); -void StringTest::testToString() { - CPPUNIT_ASSERT ( ext::to_string ( std::string ( "1" ) ) == "1" ); - CPPUNIT_ASSERT ( ext::to_string ( 1 ) == "1" ); - CPPUNIT_ASSERT ( ext::to_string ( 1ul ) == "1" ); + A a; + CHECK ( ext::to_string ( a ) == "" ); + } - StringTest::A a; - CPPUNIT_ASSERT ( ext::to_string ( a ) == "" ); -} + SECTION ( "Explode" ) { + { + std::string one ( "a::bb::ccc" ); + ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); -void StringTest::testExplode ( ) { - { - std::string one ( "a::bb::ccc" ); - ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); + CAPTURE ( oneExploded ); - std::cout << oneExploded << std::endl; + CHECK ( oneExploded.size ( ) == 3 ); + CHECK ( oneExploded [ 0 ] == "a" ); + CHECK ( oneExploded [ 1 ] == "bb" ); + CHECK ( oneExploded [ 2 ] == "ccc" ); + } + { + std::string one ( "a::bb::ccc::" ); + ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); - CPPUNIT_ASSERT ( oneExploded.size ( ) == 3 ); - CPPUNIT_ASSERT ( oneExploded [ 0 ] == "a" ); - CPPUNIT_ASSERT ( oneExploded [ 1 ] == "bb" ); - CPPUNIT_ASSERT ( oneExploded [ 2 ] == "ccc" ); - } - { - std::string one ( "a::bb::ccc::" ); - ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); + CHECK ( oneExploded.size ( ) == 4 ); + CHECK ( oneExploded [ 0 ] == "a" ); + CHECK ( oneExploded [ 1 ] == "bb" ); + CHECK ( oneExploded [ 2 ] == "ccc" ); + CHECK ( oneExploded [ 3 ] == "" ); + } + { + std::string one ( "" ); + ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); - CPPUNIT_ASSERT ( oneExploded.size ( ) == 4 ); - CPPUNIT_ASSERT ( oneExploded [ 0 ] == "a" ); - CPPUNIT_ASSERT ( oneExploded [ 1 ] == "bb" ); - CPPUNIT_ASSERT ( oneExploded [ 2 ] == "ccc" ); - CPPUNIT_ASSERT ( oneExploded [ 3 ] == "" ); - } - { - std::string one ( "" ); - ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); - - CPPUNIT_ASSERT ( oneExploded.size ( ) == 1 ); - CPPUNIT_ASSERT ( oneExploded [ 0 ] == "" ); - } - { - std::string one ( "::aa" ); - ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); + CHECK ( oneExploded.size ( ) == 1 ); + CHECK ( oneExploded [ 0 ] == "" ); + } + { + std::string one ( "::aa" ); + ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); - std::cout << oneExploded << std::endl; + CAPTURE ( oneExploded ); - CPPUNIT_ASSERT ( oneExploded.size ( ) == 2 ); - CPPUNIT_ASSERT ( oneExploded [ 0 ] == "" ); - CPPUNIT_ASSERT ( oneExploded [ 1 ] == "aa" ); - } - { - std::string one ( "::" ); - ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); + CHECK ( oneExploded.size ( ) == 2 ); + CHECK ( oneExploded [ 0 ] == "" ); + CHECK ( oneExploded [ 1 ] == "aa" ); + } + { + std::string one ( "::" ); + ext::vector < std::string > oneExploded = ext::explode ( one, "::" ); - CPPUNIT_ASSERT ( oneExploded.size ( ) == 2 ); - CPPUNIT_ASSERT ( oneExploded [ 0 ] == "" ); - CPPUNIT_ASSERT ( oneExploded [ 1 ] == "" ); + CHECK ( oneExploded.size ( ) == 2 ); + CHECK ( oneExploded [ 0 ] == "" ); + CHECK ( oneExploded [ 1 ] == "" ); + } } } diff --git a/alib2std/test-src/extensions/container/StringTest.h b/alib2std/test-src/extensions/container/StringTest.h deleted file mode 100644 index 28c4c94ed3..0000000000 --- a/alib2std/test-src/extensions/container/StringTest.h +++ /dev/null @@ -1,27 +0,0 @@ -#ifndef STRING_TEST_H_ -#define STRING_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class StringTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE( StringTest ); - CPPUNIT_TEST( testToString ); - CPPUNIT_TEST( testExplode ); - CPPUNIT_TEST_SUITE_END(); - - class A { - public: - explicit operator std::string ( ) const { - return ""; - } - }; - -public: - void setUp ( ); - void tearDown ( ); - - void testToString ( ); - void testExplode ( ); -}; - -#endif /* STRING_TEST_H_ */ diff --git a/alib2std/test-src/extensions/container/TreeBaseTest.cpp b/alib2std/test-src/extensions/container/TreeBaseTest.cpp index 5dde60d3d0..e17f76ed02 100644 --- a/alib2std/test-src/extensions/container/TreeBaseTest.cpp +++ b/alib2std/test-src/extensions/container/TreeBaseTest.cpp @@ -1,47 +1,124 @@ -#include "TreeBaseTest.h" +#include <catch2/catch.hpp> +#include <alib/compare> +#include <alib/tree> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( TreeBaseTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( TreeBaseTest ); +namespace { + class RegExpElement : public ext::BaseNode < RegExpElement > { + }; -void TreeBaseTest::setUp ( ) { -} + class RegExpAlternation : public RegExpElement, public ext::VararyNode < RegExpElement, RegExpAlternation > { + public: + RegExpAlternation ( RegExpElement && left, RegExpElement && right ) : VararyNode < RegExpElement, RegExpAlternation > ( ) { + pushBackChild ( std::move ( left ) ); + pushBackChild ( std::move ( right ) ); + } + }; -void TreeBaseTest::tearDown ( ) { -} -void TreeBaseTest::testRegexps ( ) { - RegExpIteration iter = RegExpEmpty ( ); + class RegExpConcatenation : public RegExpElement, public ext::BinaryNode < RegExpElement, RegExpConcatenation > { + public: + RegExpConcatenation ( RegExpElement && left, RegExpElement && right ) : BinaryNode < RegExpElement, RegExpConcatenation > ( std::move ( left ), std::move ( right ) ) { + } + }; - CPPUNIT_ASSERT ( iter.getChild ( ).getParent ( ) == & iter ); + class RegExpIteration : public RegExpElement, public ext::UnaryNode < RegExpElement, RegExpIteration > { + public: + RegExpIteration ( RegExpElement && element ) : UnaryNode < RegExpElement, RegExpIteration > ( std::move ( element ) ) { + } + }; - RegExpIteration iter2 = iter; - RegExpIteration iter3 = iter2; + class RegExpSymbol : public RegExpElement, public ext::NullaryNode < RegExpElement, RegExpSymbol > { + char m_symbol; - CPPUNIT_ASSERT ( iter3.getChild ( ).getParent ( ) == & iter3 ); + public: + RegExpSymbol ( char symbol ) : m_symbol ( symbol ) { + } - iter3 = iter; - RegExpIteration iter4 = RegExpEpsilon ( ); - iter3 = iter4; + char getSymbol ( ) const { + return m_symbol; + } + }; - CPPUNIT_ASSERT ( iter3.getChild ( ).getParent ( ) == & iter3 ); + class RegExpEpsilon : public RegExpElement { + }; - RegExpSymbol s ( 'x' ); - const RegExpSymbol & sr = s; - sr.getChildren ( ); + class RegExpEmpty : public RegExpElement { + }; - RegExpAlternation alter ( std::move ( iter ), std::move ( iter2 ) ); - for ( const RegExpElement & element : alter.getChildren ( ) ) { - CPPUNIT_ASSERT ( element.getParent ( ) == & alter ); - } -} + class RegExp { + std::shared_ptr < RegExpElement > root; + }; + + class UnrankedTreeNode : public ext::BaseNode < UnrankedTreeNode >, public ext::VararyNode < UnrankedTreeNode > { + char m_symbol; + + public: + UnrankedTreeNode ( char symbol, ext::ptr_vector < UnrankedTreeNode > c ) : VararyNode < UnrankedTreeNode > ( std::move ( c ) ), m_symbol ( symbol ) { + } -void TreeBaseTest::testRankedTree ( ) { - RankedTreeNode node ( 'a', 1, { RankedTreeNode ( 'b', 1, { RankedTreeNode ( 'c', 0, { } ) } ) } ); - const RankedTreeNode & cnode = node; + char getSymbol ( ) const { + return m_symbol; + } + }; - for ( const RankedTreeNode & child : cnode.getChildren ( ) ) - CPPUNIT_ASSERT ( child.getParent ( ) == & cnode ); + class UnrankedTree { + UnrankedTreeNode root; + }; + + class RankedTreeNode : public ext::BaseNode < RankedTreeNode >, public ext::FixedaryNode < RankedTreeNode > { + char m_symbol; + unsigned m_arity; + + public: + RankedTreeNode ( char symbol, unsigned arity, ext::ptr_vector < RankedTreeNode > c ) : FixedaryNode < RankedTreeNode > ( std::move ( c ) ), m_symbol ( symbol ), m_arity ( arity ) { + if ( getChildren ( ).size ( ) != m_arity ) + throw "Arity != size"; + } + + char getSymbol ( ) const { + return m_symbol; + } + }; + + class RankedTree { + RankedTreeNode root; + }; } +TEST_CASE ( "TreeBase", "[unit][std][container]" ) { + SECTION ( "RegExps" ) { + RegExpIteration iter = RegExpEmpty ( ); + + CHECK ( iter.getChild ( ).getParent ( ) == & iter ); -void TreeBaseTest::testUnrankedTree ( ) { + RegExpIteration iter2 = iter; + RegExpIteration iter3 = iter2; + + CHECK ( iter3.getChild ( ).getParent ( ) == & iter3 ); + + iter3 = iter; + RegExpIteration iter4 = RegExpEpsilon ( ); + iter3 = iter4; + + CHECK ( iter3.getChild ( ).getParent ( ) == & iter3 ); + + RegExpSymbol s ( 'x' ); + const RegExpSymbol & sr = s; + sr.getChildren ( ); + + RegExpAlternation alter ( std::move ( iter ), std::move ( iter2 ) ); + for ( const RegExpElement & element : alter.getChildren ( ) ) { + CHECK ( element.getParent ( ) == & alter ); + } + } + + SECTION ( "RankedTree" ) { + RankedTreeNode node ( 'a', 1, { RankedTreeNode ( 'b', 1, { RankedTreeNode ( 'c', 0, { } ) } ) } ); + const RankedTreeNode & cnode = node; + + for ( const RankedTreeNode & child : cnode.getChildren ( ) ) + CHECK ( child.getParent ( ) == & cnode ); + } + + SECTION ( "UnrankedTree" ) { + } } diff --git a/alib2std/test-src/extensions/container/TreeBaseTest.h b/alib2std/test-src/extensions/container/TreeBaseTest.h deleted file mode 100644 index 896b2e61ae..0000000000 --- a/alib2std/test-src/extensions/container/TreeBaseTest.h +++ /dev/null @@ -1,113 +0,0 @@ -#ifndef TREE_TEST_BASE_H_ -#define TREE_TEST_BASE_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/compare> -#include <alib/tree> - -class TreeBaseTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( TreeBaseTest ); - CPPUNIT_TEST ( testRegexps ); - CPPUNIT_TEST ( testRankedTree ); - CPPUNIT_TEST ( testUnrankedTree ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - class RegExpElement : public ext::BaseNode < RegExpElement > { - }; - - class RegExpAlternation : public RegExpElement, public ext::VararyNode < RegExpElement, RegExpAlternation > { - public: - RegExpAlternation ( RegExpElement && left, RegExpElement && right ) : VararyNode < RegExpElement, RegExpAlternation > ( ) { - pushBackChild ( std::move ( left ) ); - pushBackChild ( std::move ( right ) ); - } - - }; - - - class RegExpConcatenation : public RegExpElement, public ext::BinaryNode < RegExpElement, RegExpConcatenation > { - public: - RegExpConcatenation ( RegExpElement && left, RegExpElement && right ) : BinaryNode < RegExpElement, RegExpConcatenation > ( std::move ( left ), std::move ( right ) ) { - } - - }; - - class RegExpIteration : public RegExpElement, public ext::UnaryNode < RegExpElement, RegExpIteration > { - public: - RegExpIteration ( RegExpElement && element ) : UnaryNode < RegExpElement, RegExpIteration > ( std::move ( element ) ) { - std::cout << "Here" << std::endl; - } - - }; - - class RegExpSymbol : public RegExpElement, public ext::NullaryNode < RegExpElement, RegExpSymbol > { - char m_symbol; - - public: - RegExpSymbol ( char symbol ) : m_symbol ( symbol ) { - } - - char getSymbol ( ) const { - return m_symbol; - } - - }; - - class RegExpEpsilon : public RegExpElement { - }; - - class RegExpEmpty : public RegExpElement { - }; - - class RegExp { - std::shared_ptr < RegExpElement > root; - }; - - class UnrankedTreeNode : public ext::BaseNode < UnrankedTreeNode >, public ext::VararyNode < UnrankedTreeNode > { - char m_symbol; - - public: - UnrankedTreeNode ( char symbol, ext::ptr_vector < UnrankedTreeNode > c ) : VararyNode < UnrankedTreeNode > ( std::move ( c ) ), m_symbol ( symbol ) { - } - - char getSymbol ( ) const { - return m_symbol; - } - - }; - - class UnrankedTree { - UnrankedTreeNode root; - }; - - class RankedTreeNode : public ext::BaseNode < RankedTreeNode >, public ext::FixedaryNode < RankedTreeNode > { - char m_symbol; - unsigned m_arity; - - public: - RankedTreeNode ( char symbol, unsigned arity, ext::ptr_vector < RankedTreeNode > c ) : FixedaryNode < RankedTreeNode > ( std::move ( c ) ), m_symbol ( symbol ), m_arity ( arity ) { - if ( getChildren ( ).size ( ) != m_arity ) - throw "Arity != size"; - } - - char getSymbol ( ) const { - return m_symbol; - } - - }; - - class RankedTree { - RankedTreeNode root; - }; - -public: - void setUp ( ); - void tearDown ( ); - - void testRegexps ( ); - void testRankedTree ( ); - void testUnrankedTree ( ); -}; - -#endif // TREE_TEST_BASE_H_ diff --git a/alib2std/test-src/extensions/container/TreeTest.cpp b/alib2std/test-src/extensions/container/TreeTest.cpp index 81f6cdaea2..5d751da25f 100644 --- a/alib2std/test-src/extensions/container/TreeTest.cpp +++ b/alib2std/test-src/extensions/container/TreeTest.cpp @@ -1,131 +1,141 @@ -#include "TreeTest.h" +#include <catch2/catch.hpp> #include <alib/tuple> - -#include <alib/tuple> - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( TreeTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( TreeTest ); - -void TreeTest::setUp ( ) { -} - -void TreeTest::tearDown ( ) { -} - -void TreeTest::print_tree ( const ext::tree < char > & tree, std::string indent ) { - std::cout << indent << tree.getData ( ) << std::endl; - for ( const ext::tree < char > & child : tree.getChildren ( ) ) { - print_tree ( child, indent + " " ); +#include <alib/compare> +#include <alib/tree> + +namespace { + struct RankedArityChecker { + bool operator ()( char symbol, unsigned wantedRank ) const { + switch ( symbol ) { + case 'a': + return wantedRank == 2; + + case 'b': + return wantedRank == 1; + + default: + return wantedRank == 0; + } + } + + }; + + static void print_tree ( const ext::tree < char > & tree, std::string indent ) { + std::cout << indent << tree.getData ( ) << std::endl; + for ( const ext::tree < char > & child : tree.getChildren ( ) ) { + print_tree ( child, indent + " " ); + } } } -void TreeTest::testTreeStdStructure ( ) { - ext::tree < char > t ( 'a', ext::tree < char > ( 'a' ), ext::tree < char > ( 'b', ext::tree < char > ( 'a' ), ext::tree < char > ( 'b' ) ) ); - - // std::cout << "structure t " << std::boolalpha << t.checkStructure() << std::endl; - - ext::tree < char > t2 ( 'c' ); - - // std::cout << "structure t2 " << std::boolalpha << t2.checkStructure() << std::endl; - t2.insert ( t2.begin ( ), { 'c', ext::tree < char > ( 'b' ) } ); - - std::swap ( t2.getChildren ( ).front (), t.getChildren().front ( ) ); - CPPUNIT_ASSERT ( t2 == ext::tree < char > ( 'c', ext::tree < char > ( 'a' ) ) ); - CPPUNIT_ASSERT ( t == ext::tree < char > ( 'a', ext::tree < char > ( 'c', ext::tree < char > ( 'b' ) ), ext::tree < char > ( 'b', ext::tree < char > ( 'a' ), ext::tree < char > ( 'b' ) ) ) ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); - CPPUNIT_ASSERT ( t.checkStructure ( ) ); - std::swap ( t2.getChildren ( ).front (), t.getChildren().front ( ) ); - - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); - - t2.insert ( t2.end ( ), t ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); - - ext::vector < char > data = { 'd', 'e' }; - t2.insert ( t2.end ( ), data.begin ( ), data.end ( ) ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); - - print_tree ( t, "" ); - - t2.erase ( std::prev ( t2.end ( ) ) ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); - t2.push_back ( 'f' ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); - - print_tree ( t2, "" ); - - CPPUNIT_ASSERT_EQUAL ( ( char ) t2 ( ), 'c' ); - CPPUNIT_ASSERT_EQUAL ( ( char ) t2 ( 0 ), 'c' ); - CPPUNIT_ASSERT_EQUAL ( ( char ) t2 ( 0, 0 ), 'b' ); - - CPPUNIT_ASSERT_EQUAL ( ( char ) t2 ( 1, 1 ), 'b' ); - t2 ( 1, 1 ) = 'c'; - CPPUNIT_ASSERT_EQUAL ( ( char ) t2 ( 1, 1 ), 'c' ); - - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); - ext::tree < char >::const_prefix_iterator beg = t2.prefix_begin ( ); - beg++; - beg++; - beg++; - beg++; - beg++; - beg++; - beg++; - beg--; - beg--; - beg--; - beg--; - beg--; - beg--; - beg--; - - CPPUNIT_ASSERT ( beg == t2.prefix_begin ( ) ); - std::cout << t2 << std::endl; - std::stringstream ss; - ss << t2; - CPPUNIT_ASSERT ( ss.str ( ) == "[0c[1c[2b],1a[2a,2c[3a,3b]],1d,1f]]" ); - - ext::vector < std::pair < unsigned, char > > expectedPrefix = { { 0, 'c' }, { 1, 'c' }, { 2, 'b' }, { 1, 'a' }, { 2, 'a' }, { 2, 'c' }, { 3, 'a' }, { 3, 'b' }, { 1, 'd' }, { 1, 'f' } }; - ext::vector < std::pair < unsigned, char > >::const_iterator ref = expectedPrefix.begin ( ); - - for ( ext::tree < char >::const_prefix_iterator iter = t2.prefix_begin ( ); iter != t2.prefix_end ( ); ++iter ) { - CPPUNIT_ASSERT ( iter.getLevel ( ) == ref->first ); - CPPUNIT_ASSERT ( * iter == ref->second ); - ++iter; - --iter; - ++ref; +TEST_CASE ( "Tree", "[unit][std][container]" ) { + SECTION ( "Test TreeStdStructure" ) { + ext::tree < char > t ( 'a', ext::tree < char > ( 'a' ), ext::tree < char > ( 'b', ext::tree < char > ( 'a' ), ext::tree < char > ( 'b' ) ) ); + // std::cout << "structure t " << std::boolalpha << t.checkStructure() << std::endl; + + ext::tree < char > t2 ( 'c' ); + // std::cout << "structure t2 " << std::boolalpha << t2.checkStructure() << std::endl; + t2.insert ( t2.begin ( ), { 'c', ext::tree < char > ( 'b' ) } ); + + std::swap ( t2.getChildren ( ).front (), t.getChildren().front ( ) ); + CHECK ( t2 == ext::tree < char > ( 'c', ext::tree < char > ( 'a' ) ) ); + CHECK ( t == ext::tree < char > ( 'a', ext::tree < char > ( 'c', ext::tree < char > ( 'b' ) ), ext::tree < char > ( 'b', ext::tree < char > ( 'a' ), ext::tree < char > ( 'b' ) ) ) ); + CHECK ( t2.checkStructure ( ) ); + CHECK ( t.checkStructure ( ) ); + std::swap ( t2.getChildren ( ).front (), t.getChildren().front ( ) ); + + CHECK ( t2.checkStructure ( ) ); + + t2.insert ( t2.end ( ), t ); + + CHECK ( t2.checkStructure ( ) ); + + ext::vector < char > data = { 'd', 'e' }; + t2.insert ( t2.end ( ), data.begin ( ), data.end ( ) ); + CHECK ( t2.checkStructure ( ) ); + + print_tree ( t, "" ); + + t2.erase ( std::prev ( t2.end ( ) ) ); + CHECK ( t2.checkStructure ( ) ); + t2.push_back ( 'f' ); + CHECK ( t2.checkStructure ( ) ); + + print_tree ( t2, "" ); + + CHECK ( ( char ) t2 ( ) == 'c' ); + CHECK ( ( char ) t2 ( 0 ) == 'c' ); + CHECK ( ( char ) t2 ( 0, 0 ) == 'b' ); + + CHECK ( ( char ) t2 ( 1, 1 ) == 'b' ); + t2 ( 1, 1 ) = 'c'; + CHECK ( ( char ) t2 ( 1, 1 ) == 'c' ); + + CHECK ( t2.checkStructure ( ) ); + ext::tree < char >::const_prefix_iterator beg = t2.prefix_begin ( ); + beg++; + beg++; + beg++; + beg++; + beg++; + beg++; + beg++; + beg--; + beg--; + beg--; + beg--; + beg--; + beg--; + beg--; + + CHECK ( beg == t2.prefix_begin ( ) ); + std::cout << t2 << std::endl; + std::stringstream ss; + ss << t2; + CHECK ( ss.str ( ) == "[0c[1c[2b],1a[2a,2c[3a,3b]],1d,1f]]" ); + + ext::vector < std::pair < unsigned, char > > expectedPrefix = { { 0, 'c' }, { 1, 'c' }, { 2, 'b' }, { 1, 'a' }, { 2, 'a' }, { 2, 'c' }, { 3, 'a' }, { 3, 'b' }, { 1, 'd' }, { 1, 'f' } }; + ext::vector < std::pair < unsigned, char > >::const_iterator ref = expectedPrefix.begin ( ); + + for ( ext::tree < char >::const_prefix_iterator iter = t2.prefix_begin ( ); iter != t2.prefix_end ( ); ++iter ) { + CHECK ( iter.getLevel ( ) == ref->first ); + CHECK ( * iter == ref->second ); + ++iter; + --iter; + ++ref; + } + + ext::vector < ext::tuple < unsigned, char, bool > > expectedStructure = { ext::make_tuple ( 0u, 'c', false ), ext::make_tuple ( 1u, 'c', false ), ext::make_tuple ( 2u, 'b', false ), ext::make_tuple ( 2u, 'b', true ), ext::make_tuple ( 1u, 'c', true ), ext::make_tuple ( 1u, 'a', false ), ext::make_tuple ( 2u, 'a', false ), ext::make_tuple ( 2u, 'a', true ), ext::make_tuple ( 2u, 'c', false ), ext::make_tuple ( 3u, 'a', false ), ext::make_tuple ( 3u, 'a', true ), ext::make_tuple ( 3u, 'b', false ), ext::make_tuple ( 3u, 'b', true ), ext::make_tuple ( 2u, 'c', true ), ext::make_tuple ( 1u, 'a', true ), ext::make_tuple ( 1u, 'd', false ), ext::make_tuple ( 1u, 'd', true ), ext::make_tuple ( 1u, 'f', false ), ext::make_tuple ( 1u, 'f', true ), ext::make_tuple ( 0u, 'c', true ) }; + ext::vector < ext::tuple < unsigned, char, bool > >::const_iterator ref2 = expectedStructure.begin ( ); + + for ( ext::tree < char >::const_structure_iterator iter = t2.structure_begin ( ); iter != t2.structure_end ( ); ++iter ) { + CHECK ( iter.getLevel ( ) == std::get < 0 > ( * ref2 ) ); + CHECK ( * iter == std::get < 1 > ( * ref2 ) ); + CHECK ( iter.getVirtual ( ) == std::get < 2 > ( * ref2 ) ); + ++iter; + --iter; + ++ref2; + } + + ext::vector < std::pair < unsigned, char > > expectedPostfix = { { 2, 'b' }, { 1, 'c' }, { 2, 'a' }, { 3, 'a' }, { 3, 'b' }, { 2, 'c' }, { 1, 'a' }, { 1, 'd' }, { 1, 'f' }, { 0, 'c' } }; + ext::vector < std::pair < unsigned, char > >::const_iterator ref3 = expectedPostfix.begin ( ); + + for ( ext::tree < char >::const_postfix_iterator iter = t2.postfix_begin ( ); iter != t2.postfix_end ( ); ++iter ) { + CHECK ( iter.getLevel ( ) == ref3->first ); + CHECK ( * iter == ref3->second ); + ++iter; + --iter; + ++ref3; + } + + ext::tree < char > cmp1 ( 'a' ); + ext::tree < char > cmp2 ( 'b' ); + ext::tree < char > cmp3 ( 'c' ); + + CHECK ( cmp1 < cmp2 ); + CHECK ( cmp2 < cmp3 ); + CHECK ( cmp2 <= cmp3 ); + CHECK ( cmp2 == cmp2 ); + CHECK ( cmp1 != cmp2 ); } - - ext::vector < ext::tuple < unsigned, char, bool > > expectedStructure = { ext::make_tuple ( 0u, 'c', false ), ext::make_tuple ( 1u, 'c', false ), ext::make_tuple ( 2u, 'b', false ), ext::make_tuple ( 2u, 'b', true ), ext::make_tuple ( 1u, 'c', true ), ext::make_tuple ( 1u, 'a', false ), ext::make_tuple ( 2u, 'a', false ), ext::make_tuple ( 2u, 'a', true ), ext::make_tuple ( 2u, 'c', false ), ext::make_tuple ( 3u, 'a', false ), ext::make_tuple ( 3u, 'a', true ), ext::make_tuple ( 3u, 'b', false ), ext::make_tuple ( 3u, 'b', true ), ext::make_tuple ( 2u, 'c', true ), ext::make_tuple ( 1u, 'a', true ), ext::make_tuple ( 1u, 'd', false ), ext::make_tuple ( 1u, 'd', true ), ext::make_tuple ( 1u, 'f', false ), ext::make_tuple ( 1u, 'f', true ), ext::make_tuple ( 0u, 'c', true ) }; - ext::vector < ext::tuple < unsigned, char, bool > >::const_iterator ref2 = expectedStructure.begin ( ); - - for ( ext::tree < char >::const_structure_iterator iter = t2.structure_begin ( ); iter != t2.structure_end ( ); ++iter ) { - CPPUNIT_ASSERT ( iter.getLevel ( ) == std::get < 0 > ( * ref2 ) ); - CPPUNIT_ASSERT ( * iter == std::get < 1 > ( * ref2 ) ); - CPPUNIT_ASSERT ( iter.getVirtual ( ) == std::get < 2 > ( * ref2 ) ); - ++iter; - --iter; - ++ref2; - } - - ext::vector < std::pair < unsigned, char > > expectedPostfix = { { 2, 'b' }, { 1, 'c' }, { 2, 'a' }, { 3, 'a' }, { 3, 'b' }, { 2, 'c' }, { 1, 'a' }, { 1, 'd' }, { 1, 'f' }, { 0, 'c' } }; - ext::vector < std::pair < unsigned, char > >::const_iterator ref3 = expectedPostfix.begin ( ); - - for ( ext::tree < char >::const_postfix_iterator iter = t2.postfix_begin ( ); iter != t2.postfix_end ( ); ++iter ) { - CPPUNIT_ASSERT ( iter.getLevel ( ) == ref3->first ); - CPPUNIT_ASSERT ( * iter == ref3->second ); - ++iter; - --iter; - ++ref3; - } - - ext::tree < char > cmp1 ( 'a' ); - ext::tree < char > cmp2 ( 'b' ); - ext::tree < char > cmp3 ( 'c' ); - - CPPUNIT_ASSERT ( cmp1 < cmp2 ); - CPPUNIT_ASSERT ( cmp2 < cmp3 ); - CPPUNIT_ASSERT ( cmp2 <= cmp3 ); - CPPUNIT_ASSERT ( cmp2 == cmp2 ); - CPPUNIT_ASSERT ( cmp1 != cmp2 ); } diff --git a/alib2std/test-src/extensions/container/TreeTest.h b/alib2std/test-src/extensions/container/TreeTest.h deleted file mode 100644 index 286cdcde34..0000000000 --- a/alib2std/test-src/extensions/container/TreeTest.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef TREE_TEST_H_ -#define TREE_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/compare> -#include <alib/tree> - -class TreeTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( TreeTest ); - CPPUNIT_TEST ( testTreeStdStructure ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - struct RankedArityChecker { - bool operator ()( char symbol, unsigned wantedRank ) const { - switch ( symbol ) { - case 'a': - return wantedRank == 2; - - case 'b': - return wantedRank == 1; - - default: - return wantedRank == 0; - } - } - - }; - - void print_tree ( const ext::tree < char > & tree, std::string indent ); - - void setUp ( ); - void tearDown ( ); - - void testTreeStdStructure(); -}; - -#endif // TREE_TEST_H_ diff --git a/alib2std/test-src/extensions/container/TrieTest.cpp b/alib2std/test-src/extensions/container/TrieTest.cpp index 4376f1d51c..6a0b56b667 100644 --- a/alib2std/test-src/extensions/container/TrieTest.cpp +++ b/alib2std/test-src/extensions/container/TrieTest.cpp @@ -1,73 +1,86 @@ -#include "TrieTest.h" - -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( TrieTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( TrieTest ); - -void TrieTest::setUp ( ) { -} - -void TrieTest::tearDown ( ) { -} - -void TrieTest::print_tree ( const ext::trie < char, int > & tree, std::string indent ) { - std::cout << indent << tree.getData ( ) << std::endl; - for ( const std::pair < const char, ext::trie < char, int > > & child : tree.getChildren ( ) ) { - std::cout << indent << child.first << ":" << std::endl; - print_tree ( child.second, indent + " " ); +#include <catch2/catch.hpp> +#include <alib/compare> +#include <alib/trie> + +namespace { + struct RankedArityChecker { + bool operator ()( char symbol, unsigned wantedRank ) const { + switch ( symbol ) { + case 'a': + return wantedRank == 2; + + case 'b': + return wantedRank == 1; + + default: + return wantedRank == 0; + } + } + + }; + + static void print_tree ( const ext::trie < char, int > & tree, std::string indent ) { + std::cout << indent << tree.getData ( ) << std::endl; + for ( const std::pair < const char, ext::trie < char, int > > & child : tree.getChildren ( ) ) { + std::cout << indent << child.first << ":" << std::endl; + print_tree ( child.second, indent + " " ); + } } } -void TrieTest::testTrieStdStructure ( ) { - ext::trie < char, int > t ( 0, ext::map < char, ext::trie < char, int > > { std::make_pair ( 'a', ext::trie < char, int > ( 1 ) ), std::make_pair ( 'b', ext::trie < char, int > ( 2 ) ) } ); +TEST_CASE ( "Trie", "[unit][std][container]" ) { + SECTION ( "Trie Std Structure" ) { + ext::trie < char, int > t ( 0, ext::map < char, ext::trie < char, int > > { std::make_pair ( 'a', ext::trie < char, int > ( 1 ) ), std::make_pair ( 'b', ext::trie < char, int > ( 2 ) ) } ); - // std::cout << "structure t " << std::boolalpha << t.checkStructure() << std::endl; + // std::cout << "structure t " << std::boolalpha << t.checkStructure() << std::endl; - ext::trie < char, int > t2 ( 3 ); - CPPUNIT_ASSERT ( t2 == ( ext::trie < char, int > ( 3 ) ) ); + ext::trie < char, int > t2 ( 3 ); + CHECK ( t2 == ( ext::trie < char, int > ( 3 ) ) ); - // std::cout << "structure t2 " << std::boolalpha << t2.checkStructure() << std::endl; - t2.insert ( 'c', ext::trie < char, int > ( 4 ) ); + // std::cout << "structure t2 " << std::boolalpha << t2.checkStructure() << std::endl; + t2.insert ( 'c', ext::trie < char, int > ( 4 ) ); - std::cout << t2 << std::endl; + std::cout << t2 << std::endl; - CPPUNIT_ASSERT ( t2 == ( ext::trie < char, int > ( 3, ext::map < char, ext::trie < char, int > > { std::make_pair ( 'c', ext::trie < char, int > ( 4 ) ) } ) ) ); - std::swap ( t2.getChildren ( ).begin()->second, t.getChildren().begin()->second ); - CPPUNIT_ASSERT ( t2 == ( ext::trie < char, int > ( 3, ext::map < char, ext::trie < char, int > > { std::make_pair ( 'c', ext::trie < char, int > ( 1 ) ) } ) ) ); - CPPUNIT_ASSERT ( t == ( ext::trie < char, int > ( 0, ext::map < char, ext::trie < char, int > > { std::make_pair ( 'a', ext::trie < char, int > ( 4 ) ), std::make_pair ( 'b', ext::trie < char, int > ( 2 ) ) } ) ) ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); - CPPUNIT_ASSERT ( t.checkStructure ( ) ); - std::swap ( t2.getChildren ( ).begin()->second, t.getChildren().begin()->second ); + CHECK ( t2 == ( ext::trie < char, int > ( 3, ext::map < char, ext::trie < char, int > > { std::make_pair ( 'c', ext::trie < char, int > ( 4 ) ) } ) ) ); + std::swap ( t2.getChildren ( ).begin()->second, t.getChildren().begin()->second ); + CHECK ( t2 == ( ext::trie < char, int > ( 3, ext::map < char, ext::trie < char, int > > { std::make_pair ( 'c', ext::trie < char, int > ( 1 ) ) } ) ) ); + CHECK ( t == ( ext::trie < char, int > ( 0, ext::map < char, ext::trie < char, int > > { std::make_pair ( 'a', ext::trie < char, int > ( 4 ) ), std::make_pair ( 'b', ext::trie < char, int > ( 2 ) ) } ) ) ); + CHECK ( t2.checkStructure ( ) ); + CHECK ( t.checkStructure ( ) ); + std::swap ( t2.getChildren ( ).begin()->second, t.getChildren().begin()->second ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); + CHECK ( t2.checkStructure ( ) ); - t2.insert ( t.begin ( ), t.end ( ) ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); + t2.insert ( t.begin ( ), t.end ( ) ); + CHECK ( t2.checkStructure ( ) ); - print_tree ( t2, "" ); + print_tree ( t2, "" ); - t2.erase ( std::prev ( t2.getChildren ( ).end ( ) ) ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); + t2.erase ( std::prev ( t2.getChildren ( ).end ( ) ) ); + CHECK ( t2.checkStructure ( ) ); - print_tree ( t2, "" ); + print_tree ( t2, "" ); - t2.getChildren().begin()->second.insert ( 'a', ext::trie < char, int > ( 5 ) ); + t2.getChildren().begin()->second.insert ( 'a', ext::trie < char, int > ( 5 ) ); - CPPUNIT_ASSERT_EQUAL ( ( int ) t2 ( ), 3 ); - CPPUNIT_ASSERT_EQUAL ( ( int ) t2 ( 'a' ), 1 ); - CPPUNIT_ASSERT_EQUAL ( ( int ) t2 ( 'a', 'a' ), 5 ); + CHECK ( ( int ) t2 ( ) == 3 ); + CHECK ( ( int ) t2 ( 'a' ) == 1 ); + CHECK ( ( int ) t2 ( 'a', 'a' ) == 5 ); - t2 ( 'a', 'a' ) = 6; - CPPUNIT_ASSERT_EQUAL ( ( int ) t2 ( 'a', 'a' ), 6 ); + t2 ( 'a', 'a' ) = 6; + CHECK ( ( int ) t2 ( 'a', 'a' ) == 6 ); - CPPUNIT_ASSERT ( t2.checkStructure ( ) ); + CHECK ( t2.checkStructure ( ) ); - ext::trie < char, int > cmp1 ( 1 ); - ext::trie < char, int > cmp2 ( 2 ); - ext::trie < char, int > cmp3 ( 3 ); + ext::trie < char, int > cmp1 ( 1 ); + ext::trie < char, int > cmp2 ( 2 ); + ext::trie < char, int > cmp3 ( 3 ); - CPPUNIT_ASSERT ( cmp1 < cmp2 ); - CPPUNIT_ASSERT ( cmp2 < cmp3 ); - CPPUNIT_ASSERT ( cmp2 <= cmp3 ); - CPPUNIT_ASSERT ( cmp2 == cmp2 ); - CPPUNIT_ASSERT ( cmp1 != cmp2 ); + CHECK ( cmp1 < cmp2 ); + CHECK ( cmp2 < cmp3 ); + CHECK ( cmp2 <= cmp3 ); + CHECK ( cmp2 == cmp2 ); + CHECK ( cmp1 != cmp2 ); + } } diff --git a/alib2std/test-src/extensions/container/TrieTest.h b/alib2std/test-src/extensions/container/TrieTest.h deleted file mode 100644 index a67e8ce0f1..0000000000 --- a/alib2std/test-src/extensions/container/TrieTest.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef TRIE_TEST_H_ -#define TRIE_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/compare> -#include <alib/trie> - -class TrieTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( TrieTest ); - CPPUNIT_TEST ( testTrieStdStructure ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - struct RankedArityChecker { - bool operator ()( char symbol, unsigned wantedRank ) const { - switch ( symbol ) { - case 'a': - return wantedRank == 2; - - case 'b': - return wantedRank == 1; - - default: - return wantedRank == 0; - } - } - - }; - - void print_tree ( const ext::trie < char, int > & trie, std::string indent ); - - void setUp ( ); - void tearDown ( ); - - void testTrieStdStructure(); -}; - -#endif // TRIE_TEST_H_ diff --git a/alib2std/test-src/extensions/container/TupleTest.cpp b/alib2std/test-src/extensions/container/TupleTest.cpp index 89c4c83992..c28f23d2a6 100644 --- a/alib2std/test-src/extensions/container/TupleTest.cpp +++ b/alib2std/test-src/extensions/container/TupleTest.cpp @@ -1,24 +1,17 @@ -#include "TupleTest.h" +#include <catch2/catch.hpp> #include <alib/tuple> #include <sstream> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( TupleTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( TupleTest ); +TEST_CASE ( "Tuple", "[unit][std][container]" ) { + SECTION ( "Test call on nth" ) { + ext::tuple < int, int, int, int, int > t = ext::make_tuple ( 1, 2, 3, 4, 5 ); -void TupleTest::setUp() { -} - -void TupleTest::tearDown() { -} - -void TupleTest::testCallOnNth() { - ext::tuple < int, int, int, int, int > t = ext::make_tuple ( 1, 2, 3, 4, 5 ); - - CPPUNIT_ASSERT ( ext::call_on_nth < int > ( t, 1, [] ( int i ) { return i; } ) == 2 ); + CHECK ( ext::call_on_nth < int > ( t, 1, [] ( int i ) { return i; } ) == 2 ); - std::stringstream ss; - ss << t; - std::cout << ss.str ( ) << std::endl; - CPPUNIT_ASSERT ( ss.str ( ) == "(1, 2, 3, 4, 5)" ); + std::stringstream ss; + ss << t; + CAPTURE ( ss.str ( ) ); + CHECK ( ss.str ( ) == "(1, 2, 3, 4, 5)" ); + } } diff --git a/alib2std/test-src/extensions/container/TupleTest.h b/alib2std/test-src/extensions/container/TupleTest.h deleted file mode 100644 index feaa2b86d0..0000000000 --- a/alib2std/test-src/extensions/container/TupleTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef TUPLE_TEST_H_ -#define TUPLE_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class TupleTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( TupleTest ); - CPPUNIT_TEST( testCallOnNth ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testCallOnNth(); -}; - -#endif // TUPLE_TEST_H_ diff --git a/alib2std/test-src/extensions/container/VariantTest.cpp b/alib2std/test-src/extensions/container/VariantTest.cpp index 4c09114f49..c2caab817f 100644 --- a/alib2std/test-src/extensions/container/VariantTest.cpp +++ b/alib2std/test-src/extensions/container/VariantTest.cpp @@ -1,220 +1,269 @@ -#include "VariantTest.h" +#include <catch2/catch.hpp> #include <alib/variant> #include <alib/set> #include <alib/algorithm> #include <alib/map> #include <sstream> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VariantTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( VariantTest ); - -void VariantTest::setUp() { -} - -void VariantTest::tearDown() { +namespace { + struct test { + int * holder; + + test() { + //std::cout << "test()" << std::endl; + holder = new int(); + } + + test(test&& old) : holder(nullptr) { + //std::cout << "test(test&&)" << std::endl; + std::swap(holder,old.holder); + } + + test(const test& old) { + //std::cout << "test(const test&)" << std::endl; + holder = new int(*old.holder); + } + + ~test() + { + //std::cout << "~test()" << std::endl; + delete holder; + } + + bool operator<(const test& other) const { + return *(this->holder) < *(other.holder); + } + + bool operator==(const test& other) const { + return *(this->holder) == *(other.holder); + } + + int compare(const test& other) const { + return *(this->holder) - *(other.holder); + } + + friend std::ostream& operator<<(std::ostream& out, const test& other) { + out << *(other.holder); + return out; + } + + operator std::string ( ) const { + return ext::to_string ( * holder ); + } + }; + + struct test2 { + int m_i; + + test2(int i) : m_i(i) {} + }; } -void VariantTest::testVariant() { - ext::variant<int, std::string, VariantTest::test> d(10); - CPPUNIT_ASSERT( d.is<int>() ); - CPPUNIT_ASSERT( d.get<int>() == 10 ); - CPPUNIT_ASSERT( d == 10 ); - CPPUNIT_ASSERT( 10 == d ); - - std::string str = "abcde"; - d.set<std::string>(str); - CPPUNIT_ASSERT( d.is<std::string>() ); - CPPUNIT_ASSERT( d.get<std::string>() == str ); - - d.set<VariantTest::test>(VariantTest::test()); - *(d.get<VariantTest::test>().holder) = 42; - - VariantTest::test tmp; - *(tmp.holder) = 42; - CPPUNIT_ASSERT( d.is<VariantTest::test>() ); - CPPUNIT_ASSERT( d.get<VariantTest::test>() == tmp ); - - ext::variant<int, std::string, VariantTest::test> e(d); - CPPUNIT_ASSERT( e.get<VariantTest::test>() == tmp ); +namespace ext { - *(e.get<VariantTest::test>().holder) = 43; + template<> + struct compare<test> { + int operator()(const test& first, const test& second) { + return first.compare(second); + } + }; - CPPUNIT_ASSERT( (d < e) == true ); - CPPUNIT_ASSERT( (e < d) == false ); +} /* namespace ext */ - std::swap ( d, e ); +TEST_CASE ( "Variant", "[unit][std][container]" ) { + SECTION ( "Variant" ) { + ext::variant<int, std::string, test> d(10); + CHECK( d.is<int>() ); + CHECK( d.get<int>() == 10 ); + CHECK( d == 10 ); + CHECK( 10 == d ); - CPPUNIT_ASSERT( (d < e) == false ); - CPPUNIT_ASSERT( (e < d) == true ); + std::string str = "abcde"; + d.set<std::string>(str); + CHECK( d.is<std::string>() ); + CHECK( d.get<std::string>() == str ); - std::swap ( d, e ); + d.set<test>(test()); + *(d.get<test>().holder) = 42; - CPPUNIT_ASSERT( (e == d) == false ); + test tmp; + *(tmp.holder) = 42; + CHECK( d.is<test>() ); + CHECK( d.get<test>() == tmp ); - d = ext::variant<int, std::string, VariantTest::test>(0); - d = e; + ext::variant<int, std::string, test> e(d); + CHECK( e.get<test>() == tmp ); - CPPUNIT_ASSERT( *(d.get<VariantTest::test>().holder) == 43 ); + *(e.get<test>().holder) = 43; - CPPUNIT_ASSERT( (d < e) == false ); - CPPUNIT_ASSERT( (e < d) == false ); + CHECK( (d < e) == true ); + CHECK( (e < d) == false ); - CPPUNIT_ASSERT( (e == d) == true ); + std::swap ( d, e ); - CPPUNIT_ASSERT ( ( ( std::string ) e ) == "43" ); + CHECK( (d < e) == false ); + CHECK( (e < d) == true ); - std::stringstream ss; - ss << e; - CPPUNIT_ASSERT ( ss.str ( ) == "43" ); -} - -void VariantTest::testVariantSet() { - VariantTest::test tmp; - *(tmp.holder) = 42; + std::swap ( d, e ); - std::string str = "abcde"; + CHECK( (e == d) == false ); - ext::variant<int, std::string, VariantTest::test> d(VariantTest::test {}); - *(d.get<VariantTest::test>().holder) = 42; - ext::variant<int, std::string, VariantTest::test> e(d); + d = ext::variant<int, std::string, test>(0); + d = e; - ext::variant<int, std::string, VariantTest::test> f(5); + CHECK( *(d.get<test>().holder) == 43 ); - ext::variant<int, std::string, VariantTest::test> g(str); + CHECK( (d < e) == false ); + CHECK( (e < d) == false ); - ext::set<ext::variant<int, std::string, VariantTest::test>> testSet; - testSet.insert(d); - testSet.insert(e); - testSet.insert(f); - testSet.insert(g); + CHECK( (e == d) == true ); - CPPUNIT_ASSERT( testSet.size() == 3 ); + CHECK ( ( ( std::string ) e ) == "43" ); - for(ext::set<ext::variant<int, std::string, VariantTest::test>>::const_iterator iter = testSet.begin(); iter != testSet.end(); iter++) { - if(iter->is<int>()) - CPPUNIT_ASSERT( iter->get<int>() == 5); - if(iter->is<std::string>()) - CPPUNIT_ASSERT( iter->get<std::string>() == str ); - if(iter->is<VariantTest::test>()) - CPPUNIT_ASSERT( iter->get<VariantTest::test>() == tmp ); + std::stringstream ss; + ss << e; + CHECK ( ss.str ( ) == "43" ); } - ext::variant<VariantTest::test2, std::string, VariantTest::test> h("aa"); - CPPUNIT_ASSERT( h.is<std::string>() ); + SECTION ( "set" ) { + test tmp; + *(tmp.holder) = 42; - ext::map<ext::variant<std::string, int>, int> testMap; - testMap.insert(ext::variant<std::string, int> {"aa"}, 10); + std::string str = "abcde"; - CPPUNIT_ASSERT( testMap.size() == 1 ); - CPPUNIT_ASSERT( testMap.find(ext::variant<std::string, int> {"aa"}) != testMap.end() ); - CPPUNIT_ASSERT( testMap.find(ext::variant<std::string, int> {10}) == testMap.end() ); + ext::variant<int, std::string, test> d(test {}); + *(d.get<test>().holder) = 42; + ext::variant<int, std::string, test> e(d); + ext::variant<int, std::string, test> f(5); + ext::variant<int, std::string, test> g(str); - testMap.insert(ext::variant<std::string, int> {"ab"}, 11); - testMap.insert(ext::variant<std::string, int> {3}, 13); + ext::set<ext::variant<int, std::string, test>> testSet; + testSet.insert(d); + testSet.insert(e); + testSet.insert(f); + testSet.insert(g); - CPPUNIT_ASSERT( testMap.find(ext::variant<std::string, int> {"aa"}) != testMap.end() ); - CPPUNIT_ASSERT( testMap.find(ext::variant<std::string, int> {10}) == testMap.end() ); -} + CHECK( testSet.size() == 3 ); -void VariantTest::testVariantSet2() { - ext::set<ext::variant<std::string, int>> s, t, u; - s.insert(std::string { "aa" } ); - s.insert(123); + for(ext::set<ext::variant<int, std::string, test>>::const_iterator iter = testSet.begin(); iter != testSet.end(); iter++) { + if(iter->is<int>()) + CHECK( iter->get<int>() == 5); + if(iter->is<std::string>()) + CHECK( iter->get<std::string>() == str ); + if(iter->is<test>()) + CHECK( iter->get<test>() == tmp ); + } - std::set_union(s.begin(), s.end(), t.begin(), t.end(), std::inserter(u, u.begin())); + ext::variant<test2, std::string, test> h("aa"); + CHECK( h.is<std::string>() ); - CPPUNIT_ASSERT( s.size() == u.size()); + ext::map<ext::variant<std::string, int>, int> testMap; + testMap.insert(ext::variant<std::string, int> {"aa"}, 10); -/* ext::variant < void, ext::pair < int, int > > var; - var.get < int > ( );*/ //should not compile -- correct behavior + CHECK( testMap.size() == 1 ); + CHECK( testMap.find(ext::variant<std::string, int> {"aa"}) != testMap.end() ); + CHECK( testMap.find(ext::variant<std::string, int> {10}) == testMap.end() ); -// ext::variant < int, char > var2;// should not compile -- correct behavior -} + testMap.insert(ext::variant<std::string, int> {"ab"}, 11); + testMap.insert(ext::variant<std::string, int> {3}, 13); -void VariantTest::testVariantVoid() { - ext::variant<void, int> i(1); - ext::variant<void, int> v; + CHECK( testMap.find(ext::variant<std::string, int> {"aa"}) != testMap.end() ); + CHECK( testMap.find(ext::variant<std::string, int> {10}) == testMap.end() ); + } - CPPUNIT_ASSERT ( v.is < void > ( ) ); - CPPUNIT_ASSERT ( i.is < int > ( ) ); + SECTION ( "set 2" ) { + ext::set<ext::variant<std::string, int>> s, t, u; + s.insert(std::string { "aa" } ); + s.insert(123); - i.set(); - CPPUNIT_ASSERT ( i.is < void > ( ) ); + std::set_union(s.begin(), s.end(), t.begin(), t.end(), std::inserter(u, u.begin())); + CHECK( s.size() == u.size()); - ext::variant<void, int> copy = i; + /* ext::variant < void, ext::pair < int, int > > var; + var.get < int > ( );*/ //should not compile -- correct behavior - CPPUNIT_ASSERT ( copy == v ); + // ext::variant < int, char > var2;// should not compile -- correct behavior + } - v = 10; + SECTION ( "void" ) { + ext::variant<void, int> i(1); + ext::variant<void, int> v; - CPPUNIT_ASSERT ( v.get<int>() == 10 ); + CHECK ( v.is < void > ( ) ); + CHECK ( i.is < int > ( ) ); - ext::variant<int, void> v2; - CPPUNIT_ASSERT ( v2.is < void > ( ) ); -} + i.set(); + CHECK ( i.is < void > ( ) ); -void VariantTest::testVariantDefault() { - ext::variant<int, std::string, void> v1 = ext::variant<int, std::string, void>::from<std::string>(); + ext::variant<void, int> copy = i; - CPPUNIT_ASSERT ( v1.get<std::string>() == ""); + CHECK ( copy == v ); - ext::variant<int, std::string, void> v2 = ext::variant<int, std::string, void>::from<void>(); + v = 10; - CPPUNIT_ASSERT ( v2.is<void> ( ) ); + CHECK ( v.get<int>() == 10 ); - ext::variant<int, std::string, void> v3 = ext::variant<int, std::string, void>::from<int>(); - - CPPUNIT_ASSERT ( v3.get<int> ( ) == 0 ); -} + ext::variant<int, void> v2; + CHECK ( v2.is < void > ( ) ); + } -void VariantTest::testVariantSameTypes() { - ext::variant < int, int, char > v1 ( 1 ); + SECTION ( "Default" ) { + ext::variant<int, std::string, void> v1 = ext::variant<int, std::string, void>::from<std::string>(); + CHECK ( v1.get<std::string>() == ""); - CPPUNIT_ASSERT ( v1.get < int > ( ) == 1 ); + ext::variant<int, std::string, void> v2 = ext::variant<int, std::string, void>::from<void>(); + CHECK ( v2.is<void> ( ) ); - v1.set < char > ( 'a' ); + ext::variant<int, std::string, void> v3 = ext::variant<int, std::string, void>::from<int>(); + CHECK ( v3.get<int> ( ) == 0 ); + } - CPPUNIT_ASSERT ( v1.get < char > ( ) == 'a' ); + SECTION ( "Same types" ) { + ext::variant < int, int, char > v1 ( 1 ); + CHECK ( v1.get < int > ( ) == 1 ); - v1.set < int > ( 'a' ); + v1.set < char > ( 'a' ); + CHECK ( v1.get < char > ( ) == 'a' ); - CPPUNIT_ASSERT ( v1.is < int > ( ) ); -} + v1.set < int > ( 'a' ); + CHECK ( v1.is < int > ( ) ); + } -void VariantTest::testSizeT() { - ext::variant < size_t, int, void > a ( ( size_t ) 1 ); - ext::variant < size_t, int, void > b ( 1 ); - ext::variant < size_t, int, void > c; + SECTION ( "size_t" ) { + ext::variant < size_t, int, void > a ( ( size_t ) 1 ); + ext::variant < size_t, int, void > b ( 1 ); + ext::variant < size_t, int, void > c; - CPPUNIT_ASSERT ( a.is < size_t > ( ) ); - CPPUNIT_ASSERT ( b.is < int > ( ) ); - CPPUNIT_ASSERT ( c.is < void > ( ) ); -} + CHECK ( a.is < size_t > ( ) ); + CHECK ( b.is < int > ( ) ); + CHECK ( c.is < void > ( ) ); + } -void VariantTest::testMoveSemantics() { - CPPUNIT_ASSERT ( ( std::is_nothrow_move_constructible < ext::variant < void, int, size_t > >::value ) ); - CPPUNIT_ASSERT ( ( std::is_move_constructible < ext::variant < void, int, size_t > >::value && std::is_move_assignable < ext::variant < void, int, size_t > >::value ) ); -} + SECTION ( "Move Semantics" ) { + CHECK ( ( std::is_nothrow_move_constructible < ext::variant < void, int, size_t > >::value ) ); + CHECK ( ( std::is_move_constructible < ext::variant < void, int, size_t > >::value && std::is_move_assignable < ext::variant < void, int, size_t > >::value ) ); + } -void VariantTest::testSetVariant ( ) { - std::set < int > a; - ext::variant < void, std::set < int > > v = a; - ext::variant < void, std::set < int > > v2 = a; - v = std::move ( v2 ); - v.get < std::set < int > > ( ).insert ( 1 ); -} + SECTION ( "Variant" ) { + std::set < int > a; + ext::variant < void, std::set < int > > v = a; + ext::variant < void, std::set < int > > v2 = a; + v = std::move ( v2 ); + v.get < std::set < int > > ( ).insert ( 1 ); + } -void VariantTest::testVariantBuilder ( ) { - bool same; - same = std::is_same < ext::variant_builder < void >, ext::variant < void > >::value; - CPPUNIT_ASSERT ( same ); + SECTION ( "Variant Builder" ) { + bool same; + same = std::is_same < ext::variant_builder < void >, ext::variant < void > >::value; + CHECK ( same ); - same = std::is_same < ext::variant_builder < int, int, int >, ext::variant < int > >::value; - CPPUNIT_ASSERT ( same ); + same = std::is_same < ext::variant_builder < int, int, int >, ext::variant < int > >::value; + CHECK ( same ); - same = std::is_same < ext::variant_builder < double, int, char >, ext::variant < double, int, char > >::value; - CPPUNIT_ASSERT ( same ); + same = std::is_same < ext::variant_builder < double, int, char >, ext::variant < double, int, char > >::value; + CHECK ( same ); - same = std::is_same < ext::variant_builder < double, int, char, char, int, double >, ext::variant < char, int, double > >::value; - CPPUNIT_ASSERT ( same ); + same = std::is_same < ext::variant_builder < double, int, char, char, int, double >, ext::variant < char, int, double > >::value; + CHECK ( same ); + } } diff --git a/alib2std/test-src/extensions/container/VariantTest.h b/alib2std/test-src/extensions/container/VariantTest.h deleted file mode 100644 index d8205974e6..0000000000 --- a/alib2std/test-src/extensions/container/VariantTest.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef VARIANT_TEST_H_ -#define VARIANT_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/compare> -#include <alib/string> - -class VariantTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( VariantTest ); - CPPUNIT_TEST( testVariant ); - CPPUNIT_TEST( testVariantSet ); - CPPUNIT_TEST( testVariantSet2 ); - CPPUNIT_TEST( testVariantVoid ); - CPPUNIT_TEST( testVariantDefault ); - CPPUNIT_TEST( testVariantSameTypes ); - CPPUNIT_TEST( testSizeT ); - CPPUNIT_TEST( testMoveSemantics ); - CPPUNIT_TEST( testSetVariant ); - CPPUNIT_TEST( testVariantBuilder ); - CPPUNIT_TEST_SUITE_END(); - -public: -struct test { - int * holder; - - test() { - //std::cout << "test()" << std::endl; - holder = new int(); - } - - test(test&& old) : holder(nullptr) { - //std::cout << "test(test&&)" << std::endl; - std::swap(holder,old.holder); - } - - test(const test& old) { - //std::cout << "test(const test&)" << std::endl; - holder = new int(*old.holder); - } - - ~test() - { - //std::cout << "~test()" << std::endl; - delete holder; - } - - bool operator<(const test& other) const { - return *(this->holder) < *(other.holder); - } - - bool operator==(const test& other) const { - return *(this->holder) == *(other.holder); - } - - int compare(const test& other) const { - return *(this->holder) - *(other.holder); - } - - friend std::ostream& operator<<(std::ostream& out, const test& other) { - out << *(other.holder); - return out; - } - - operator std::string ( ) const { - return ext::to_string ( * holder ); - } -}; - -struct test2 { - int m_i; - - test2(int i) : m_i(i) {} -}; - -public: - void setUp(); - void tearDown(); - - void testVariant(); - void testVariantSet(); - void testVariantSet2(); - void testVariantVoid(); - void testVariantDefault(); - void testVariantSameTypes(); - void testSizeT(); - void testMoveSemantics(); - void testSetVariant ( ); - void testVariantBuilder ( ); -}; - -namespace ext { - -template<> -struct compare<VariantTest::test> { - int operator()(const VariantTest::test& first, const VariantTest::test& second) { - return first.compare(second); - } -}; - -} /* namespace ext */ - -#endif // VARIANT_TEST_H_ diff --git a/alib2std/test-src/extensions/container/VectorTest.cpp b/alib2std/test-src/extensions/container/VectorTest.cpp index 7d41543bf9..4bfe6c3ac7 100644 --- a/alib2std/test-src/extensions/container/VectorTest.cpp +++ b/alib2std/test-src/extensions/container/VectorTest.cpp @@ -1,353 +1,381 @@ -#include "VectorTest.h" +#include <catch2/catch.hpp> #include <alib/vector> #include <alib/type_traits> #include <alib/algorithm> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( VectorTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( VectorTest ); +namespace { + class Moveable { + int& m_moves; + int& m_copies; -void VectorTest::setUp() { -} + public: + Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { + m_moves = 0; + m_copies = 0; + } -void VectorTest::tearDown() { -} + Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_copies++; + } -void VectorTest::testProperties() { - ext::vector<int> data = {1, 2, 3, 4}; + Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { + m_moves++; + } - const ext::vector<int>& constData = data; + Moveable & operator = ( const Moveable & ) { + m_copies ++; + return * this; + } - CPPUNIT_ASSERT((std::is_same<decltype(constData[0]), const int&>::value)); + Moveable & operator = ( Moveable && ) { + m_moves ++; + return * this; + } - int moves; - int copies; + bool operator<(const Moveable&) const { + return false; + } + }; +} - ext::vector < Moveable > vec; - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); +TEST_CASE ( "Vector", "[unit][std][container]" ) { + SECTION ( "Properties test" ) { + ext::vector<int> data = {1, 2, 3, 4}; - vec.erase ( ext::unique ( vec.begin ( ), vec.end ( ), [ ] ( const Moveable &, const Moveable & ) { return true; } ), vec.end ( ) ); + const ext::vector<int>& constData = data; - CPPUNIT_ASSERT ( vec.size ( ) == 1 ); + CHECK((std::is_same<decltype(constData[0]), const int&>::value)); - CPPUNIT_ASSERT(copies == 0); -} + int moves; + int copies; -void VectorTest::testVectorBool() { - ext::vector < bool > A; - A.push_back ( true ); - A.push_back ( false ); - A.push_back ( true ); - A.push_back ( false ); - - ext::vector < bool > B; - B.push_back ( true ); - B.push_back ( true ); - B.push_back ( false ); - B.push_back ( false ); - - { - ext::vector < bool > C = A | B; - ext::vector < bool > D = A; - D |= B; - - ext::vector < bool > X; - X.push_back ( true ); - X.push_back ( true ); - X.push_back ( true ); - X.push_back ( false ); - - std::cout << X << std::endl; - std::cout << C << std::endl; - - CPPUNIT_ASSERT ( C == X ); - CPPUNIT_ASSERT ( D == X ); - } + ext::vector < Moveable > vec; + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); - { - ext::vector < bool > C = A & B; - ext::vector < bool > D = A; - D &= B; + vec.erase ( ext::unique ( vec.begin ( ), vec.end ( ), [ ] ( const Moveable &, const Moveable & ) { return true; } ), vec.end ( ) ); - ext::vector < bool > X; - X.push_back ( true ); - X.push_back ( false ); - X.push_back ( false ); - X.push_back ( false ); + CHECK ( vec.size ( ) == 1 ); - CPPUNIT_ASSERT ( C == X ); - CPPUNIT_ASSERT ( D == X ); + CHECK(copies == 0); } - { - ext::vector < bool > C = A ^ B; - ext::vector < bool > D = A; - D ^= B; + SECTION ( "Vector<bool>" ) { + ext::vector < bool > A; + A.push_back ( true ); + A.push_back ( false ); + A.push_back ( true ); + A.push_back ( false ); + + ext::vector < bool > B; + B.push_back ( true ); + B.push_back ( true ); + B.push_back ( false ); + B.push_back ( false ); + + { + ext::vector < bool > C = A | B; + ext::vector < bool > D = A; + D |= B; + + ext::vector < bool > X; + X.push_back ( true ); + X.push_back ( true ); + X.push_back ( true ); + X.push_back ( false ); + + CAPTURE ( X, C, D ); + + CHECK ( C == X ); + CHECK ( D == X ); + } - ext::vector < bool > X; - X.push_back ( false ); - X.push_back ( true ); - X.push_back ( true ); - X.push_back ( false ); + { + ext::vector < bool > C = A & B; + ext::vector < bool > D = A; + D &= B; - CPPUNIT_ASSERT ( C == X ); - CPPUNIT_ASSERT ( D == X ); - } -} + ext::vector < bool > X; + X.push_back ( true ); + X.push_back ( false ); + X.push_back ( false ); + X.push_back ( false ); -void testOffset ( long offset, long shift ) { - unsigned long long shadow = 0x2A76B147D6521C87ULL; - ext::vector < bool > data; + CHECK ( C == X ); + CHECK ( D == X ); + } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 16 + offset; ++ i ) { - data.push_back ( true ); - } + { + ext::vector < bool > C = A ^ B; + ext::vector < bool > D = A; + D ^= B; - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + ext::vector < bool > X; + X.push_back ( false ); + X.push_back ( true ); + X.push_back ( true ); + X.push_back ( false ); + + CHECK ( C == X ); + CHECK ( D == X ); + } } - data >>= sizeof ( unsigned long long ) * 6 + shift; - ext::vector < bool > ref; - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 10 + offset - shift; ++ i ) { - ref.push_back ( true ); - } + SECTION ( "vector<bool> 2" ) { + auto testOffset = [] ( long offset, long shift ) { + unsigned long long shadow = 0x2A76B147D6521C87ULL; + ext::vector < bool > data; - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - ref.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 16 + offset; ++ i ) { + data.push_back ( true ); + } - ref.resize ( 192 + offset ); + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } -/* std::cout << "offset = " << offset << std::endl; - std::cout << "shift = " << shift << std::endl; - std::cout << "data = " << data << std::endl; - std::cout << "ref = " << ref << std::endl;*/ + data >>= sizeof ( unsigned long long ) * 6 + shift; - CPPUNIT_ASSERT ( data == ref ); -} + ext::vector < bool > ref; + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 10 + offset - shift; ++ i ) { + ref.push_back ( true ); + } -void VectorTest::testVectorBool2() { - unsigned long long shadow = 0x2A76B147D6521C87ULL; - ext::vector < bool > data; + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + ref.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } + ref.resize ( 192 + offset ); - shadow >>= 10; - data >>= 10; + /* std::cout << "offset = " << offset << std::endl; + std::cout << "shift = " << shift << std::endl; + std::cout << "data = " << data << std::endl; + std::cout << "ref = " << ref << std::endl;*/ - ext::vector < bool > ref; - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - ref.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } + CHECK ( data == ref ); + }; - std::cout << "data = " << data << std::endl; - std::cout << "ref = " << ref << std::endl; + unsigned long long shadow = 0x2A76B147D6521C87ULL; + ext::vector < bool > data; - CPPUNIT_ASSERT ( data == ref ); + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } - for ( long i = - ( long ) sizeof ( unsigned long long ) / 2 ; i < ( long ) sizeof ( unsigned long long ) * 8; ++ i ) - for ( long j = - ( long ) sizeof ( unsigned long long ) / 2 ; j < ( long ) sizeof ( unsigned long long ) * 8; ++ j ) - testOffset ( i, j ); -} + shadow >>= 10; + data >>= 10; -void VectorTest::testVectorBool3() { - unsigned long long shadow = 0x2A76B147D6521C87ULL; - ext::vector < bool > data; + ext::vector < bool > ref; + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + ref.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + CAPTURE ( data ,ref ); + + CHECK ( data == ref ); + + for ( long i = - ( long ) sizeof ( unsigned long long ) / 2 ; i < ( long ) sizeof ( unsigned long long ) * 8; ++ i ) + for ( long j = - ( long ) sizeof ( unsigned long long ) / 2 ; j < ( long ) sizeof ( unsigned long long ) * 8; ++ j ) + testOffset ( i, j ); } - ext::vector < bool > data2 = data; - data2 >>= 64; - - data >>= 32; - data >>= 16; - data >>= 8; - data >>= 4; - data >>= 2; - data >>= 1; - data >>= 1; - - std::cout << "data = " << data << std::endl; - std::cout << "data2 = " << data2 << std::endl; - - data2 >>= 1; - data2 >>= 2; - data2 >>= 4; - data2 >>= 8; - data2 >>= 16; - data2 >>= 32; - data2 >>= 1; - - data >>= 27; - data >>= 17; - data >>= 13; - data >>= 7; - - std::cout << "data = " << data << std::endl; - std::cout << "data2 = " << data2 << std::endl; - - CPPUNIT_ASSERT ( data2 == data ); -} + SECTION ( "vector<bool> 3" ) { + unsigned long long shadow = 0x2A76B147D6521C87ULL; + ext::vector < bool > data; -void testOffset2 ( long offset, long shift ) { - unsigned long long shadow = 0x2A76B147D6521C87ULL; - ext::vector < bool > data; + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8 + offset; ++ i ) { - data.push_back ( true ); + ext::vector < bool > data2 = data; + data2 >>= 64; + + data >>= 32; + data >>= 16; + data >>= 8; + data >>= 4; + data >>= 2; + data >>= 1; + data >>= 1; + + std::cout << "data = " << data << std::endl; + std::cout << "data2 = " << data2 << std::endl; + + data2 >>= 1; + data2 >>= 2; + data2 >>= 4; + data2 >>= 8; + data2 >>= 16; + data2 >>= 32; + data2 >>= 1; + + data >>= 27; + data >>= 17; + data >>= 13; + data >>= 7; + + std::cout << "data = " << data << std::endl; + std::cout << "data2 = " << data2 << std::endl; + + CHECK ( data2 == data ); } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } - data <<= sizeof ( unsigned long long ) * 2 + shift; + SECTION ( "vector<bool> 4" ) { + auto testOffset = [] ( long offset, long shift ) { + unsigned long long shadow = 0x2A76B147D6521C87ULL; + ext::vector < bool > data; - ext::vector < bool > ref; - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 2 + shift; ++ i ) { - ref.push_back ( false ); - } + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8 + offset; ++ i ) { + data.push_back ( true ); + } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8 + offset; ++ i ) { - ref.push_back ( true ); - } + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - ref.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } + data <<= sizeof ( unsigned long long ) * 2 + shift; - ref.resize ( 128 + offset ); + ext::vector < bool > ref; + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 2 + shift; ++ i ) { + ref.push_back ( false ); + } -/* std::cout << "offset = " << offset << std::endl; - std::cout << "shift = " << shift << std::endl; - std::cout << "data = " << data << std::endl; - std::cout << "ref = " << ref << std::endl;*/ + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8 + offset; ++ i ) { + ref.push_back ( true ); + } - CPPUNIT_ASSERT ( data == ref ); -} + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + ref.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } -void VectorTest::testVectorBool4() { - unsigned long long shadow = 0x2A76B147D6521C87ULL; - ext::vector < bool > data; + ref.resize ( 128 + offset ); - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } + /* std::cout << "offset = " << offset << std::endl; + std::cout << "shift = " << shift << std::endl; + std::cout << "data = " << data << std::endl; + std::cout << "ref = " << ref << std::endl;*/ - shadow <<= 10; - data <<= 10; + CHECK ( data == ref ); + }; - ext::vector < bool > ref; - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - ref.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } + unsigned long long shadow = 0x2A76B147D6521C87ULL; + ext::vector < bool > data; + + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } - std::cout << "data = " << data << std::endl; - std::cout << "ref = " << ref << std::endl; + shadow <<= 10; + data <<= 10; - CPPUNIT_ASSERT ( data == ref ); + ext::vector < bool > ref; + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + ref.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } - for ( long i = - ( long ) sizeof ( unsigned long long ) / 2 ; i < ( long ) sizeof ( unsigned long long ) * 8; ++ i ) - for ( long j = - ( long ) sizeof ( unsigned long long ) / 2 ; j < ( long ) sizeof ( unsigned long long ) * 8; ++ j ) - testOffset2 ( i, j ); -} + std::cout << "data = " << data << std::endl; + std::cout << "ref = " << ref << std::endl; -void VectorTest::testVectorBool5() { - unsigned long long shadow = 0x2A76B147D6521C87ULL; - ext::vector < bool > data; + CHECK ( data == ref ); - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); - } - for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { - data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + for ( long i = - ( long ) sizeof ( unsigned long long ) / 2 ; i < ( long ) sizeof ( unsigned long long ) * 8; ++ i ) + for ( long j = - ( long ) sizeof ( unsigned long long ) / 2 ; j < ( long ) sizeof ( unsigned long long ) * 8; ++ j ) + testOffset ( i, j ); } - ext::vector < bool > data2 = data; - data2 <<= 64; - - data <<= 32; - data <<= 16; - data <<= 8; - data <<= 4; - data <<= 2; - data <<= 1; - data <<= 1; - - std::cout << "data = " << data << std::endl; - std::cout << "data2 = " << data2 << std::endl; - - data2 <<= 1; - data2 <<= 2; - data2 <<= 4; - data2 <<= 8; - data2 <<= 16; - data2 <<= 32; - data2 <<= 1; - - data <<= 27; - data <<= 17; - data <<= 13; - data <<= 7; - - std::cout << "data = " << data << std::endl; - std::cout << "data2 = " << data2 << std::endl; - - CPPUNIT_ASSERT ( data2 == data ); -} + SECTION ( "vector<bool> 5" ) { + unsigned long long shadow = 0x2A76B147D6521C87ULL; + ext::vector < bool > data; + + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } + for ( unsigned i = 0; i < sizeof ( unsigned long long ) * 8; ++ i ) { + data.push_back ( ( bool ) ( shadow & ( 1ULL << i ) ) ); + } -void VectorTest::testVectorBool6 ( ) { - for ( size_t i = 1; i < 1000; i += 31 ) { - for ( size_t j = 1; j < 1000; j += 31 ) { - ext::vector < bool > first; - ext::vector < bool > second; + ext::vector < bool > data2 = data; + data2 <<= 64; + + data <<= 32; + data <<= 16; + data <<= 8; + data <<= 4; + data <<= 2; + data <<= 1; + data <<= 1; + + std::cout << "data = " << data << std::endl; + std::cout << "data2 = " << data2 << std::endl; + + data2 <<= 1; + data2 <<= 2; + data2 <<= 4; + data2 <<= 8; + data2 <<= 16; + data2 <<= 32; + data2 <<= 1; + + data <<= 27; + data <<= 17; + data <<= 13; + data <<= 7; + + std::cout << "data = " << data << std::endl; + std::cout << "data2 = " << data2 << std::endl; + + CHECK ( data2 == data ); + } - first.resize ( i ); - second.resize ( j ); + SECTION ( "vector<bool> 6" ) { + for ( size_t i = 1; i < 1000; i += 31 ) { + for ( size_t j = 1; j < 1000; j += 31 ) { + ext::vector < bool > first; + ext::vector < bool > second; - ext::fill ( first ); - ext::clear ( second ); + first.resize ( i ); + second.resize ( j ); - ext::vector < bool > res = first & second; + ext::fill ( first ); + ext::clear ( second ); - CPPUNIT_ASSERT ( ext::any ( res ) == false ); + ext::vector < bool > res = first & second; + + CHECK ( ext::any ( res ) == false ); + } } } -} -void VectorTest::testRange ( ) { - ext::vector < int > data { 1, 2, 3, 4 }; - ext::vector < int > data2 ( data.range ( ) ); + SECTION ( "Test Range" ) { + ext::vector < int > data { 1, 2, 3, 4 }; + ext::vector < int > data2 ( data.range ( ) ); - CPPUNIT_ASSERT ( data == data2 ); + CHECK ( data == data2 ); - int moves; - int copies; + int moves; + int copies; - ext::vector < Moveable > vec; - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); - vec.push_back ( Moveable ( moves, copies ) ); + ext::vector < Moveable > vec; + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); + vec.push_back ( Moveable ( moves, copies ) ); - ext::vector < Moveable > vec2 ( ext::range ( std::move ( vec ) ) ); + ext::vector < Moveable > vec2 ( ext::range ( std::move ( vec ) ) ); - CPPUNIT_ASSERT ( copies == 0 ); + CHECK ( copies == 0 ); + } } diff --git a/alib2std/test-src/extensions/container/VectorTest.h b/alib2std/test-src/extensions/container/VectorTest.h deleted file mode 100644 index d9b0dc6836..0000000000 --- a/alib2std/test-src/extensions/container/VectorTest.h +++ /dev/null @@ -1,68 +0,0 @@ -#ifndef VECTOR_TEST_H_ -#define VECTOR_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> -#include <alib/compare> - -class VectorTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( VectorTest ); - CPPUNIT_TEST( testProperties ); - CPPUNIT_TEST( testVectorBool ); - CPPUNIT_TEST( testVectorBool2 ); - CPPUNIT_TEST( testVectorBool3 ); - CPPUNIT_TEST( testVectorBool4 ); - CPPUNIT_TEST( testVectorBool5 ); - CPPUNIT_TEST( testVectorBool6 ); - CPPUNIT_TEST( testRange ); - CPPUNIT_TEST_SUITE_END(); - -public: -class Moveable { - int& m_moves; - int& m_copies; - -public: - Moveable(int& moves, int& copies) : m_moves(moves), m_copies(copies) { - m_moves = 0; - m_copies = 0; - } - - Moveable(const Moveable& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_copies++; - } - - Moveable(Moveable&& src) : m_moves(src.m_moves), m_copies(src.m_copies) { - m_moves++; - } - - Moveable & operator = ( const Moveable & ) { - m_copies ++; - return * this; - } - - Moveable & operator = ( Moveable && ) { - m_moves ++; - return * this; - } - - bool operator<(const Moveable&) const { - return false; - } -}; - -public: - void setUp(); - void tearDown(); - - void testProperties(); - void testVectorBool(); - void testVectorBool2(); - void testVectorBool3(); - void testVectorBool4(); - void testVectorBool5(); - void testVectorBool6(); - void testRange ( ); -}; - -#endif // VECTOR_TEST_H_ diff --git a/alib2std/test-src/extensions/container/managed/ManagedLinearSetTest.cpp b/alib2std/test-src/extensions/container/managed/ManagedLinearSetTest.cpp index 5e52e3502b..d7a8f65969 100644 --- a/alib2std/test-src/extensions/container/managed/ManagedLinearSetTest.cpp +++ b/alib2std/test-src/extensions/container/managed/ManagedLinearSetTest.cpp @@ -1,51 +1,44 @@ -#include "ManagedLinearSetTest.h" +#include <catch2/catch.hpp> #include <exception> #include <alib/managed_linear_set> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( ManagedLinearSetTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( ManagedLinearSetTest ); +TEST_CASE ( "ManagedLinearSet", "[unit][std][container]" ) { + SECTION ( "ManagedLinearSet" ) { + ext::managed_linear_set < int > mod2; + mod2.addInsertCallback ( [](const int & value) { if ( value % 2 != 0 ) throw value; } ); + CHECK_NOTHROW ( mod2.insert ( 12 ) ); + CHECK_THROWS_AS ( mod2.insert ( 13 ), int ); -void ManagedLinearSetTest::setUp ( ) { -} - -void ManagedLinearSetTest::tearDown ( ) { -} - -void ManagedLinearSetTest::testBasics ( ) { - ext::managed_linear_set < int > mod2; - mod2.addInsertCallback ( [](const int & value) { if ( value % 2 != 0 ) throw value; } ); - CPPUNIT_ASSERT_NO_THROW ( mod2.insert ( 12 ) ); - CPPUNIT_ASSERT_THROW ( mod2.insert ( 13 ), int ); - - ext::managed_linear_set < int > mod6; - mod6.addInsertCallback ( [](const int & value) { if ( value % 6 != 0 ) throw value; } ); - CPPUNIT_ASSERT_NO_THROW ( mod6.insert ( 6 ) ); - CPPUNIT_ASSERT_THROW ( mod6.insert ( 4 ), int ); + ext::managed_linear_set < int > mod6; + mod6.addInsertCallback ( [](const int & value) { if ( value % 6 != 0 ) throw value; } ); + CHECK_NOTHROW ( mod6.insert ( 6 ) ); + CHECK_THROWS_AS ( mod6.insert ( 4 ), int ); - CPPUNIT_ASSERT_NO_THROW ( std::swap ( mod2, mod6 ) ); + CHECK_NOTHROW ( std::swap ( mod2, mod6 ) ); - mod2.insert ( 4 ); + mod2.insert ( 4 ); - mod2.addInsertCallback ( [](const int & value) { std::cout << "mod2 added: " << value << std::endl; } ); - mod2.addRemoveCallback ( [](const int & value) { std::cout << "mod2 removed: " << value << std::endl; } ); - mod6.addInsertCallback ( [](const int & value) { std::cout << "mod6 added: " << value << std::endl; } ); - mod6.addRemoveCallback ( [](const int & value) { std::cout << "mod6 removed: " << value << std::endl; } ); + mod2.addInsertCallback ( [](const int & value) { INFO ("mod2 added: " << value ); } ); + mod2.addRemoveCallback ( [](const int & value) { INFO ("mod2 removed: " << value ); } ); + mod6.addInsertCallback ( [](const int & value) { INFO ("mod6 added: " << value ); } ); + mod6.addRemoveCallback ( [](const int & value) { INFO ("mod6 removed: " << value ); } ); - std::cout << "mod2: " << mod2 << std::endl; - std::cout << "mod6: " << mod6 << std::endl; - CPPUNIT_ASSERT_THROW ( std::swap ( mod2, mod6 ), int ); - std::cout << "mod2: " << mod2 << std::endl; - std::cout << "mod6: " << mod6 << std::endl; - CPPUNIT_ASSERT_THROW ( swap ( mod2, mod6 ), int ); - std::cout << "mod2: " << mod2 << std::endl; - std::cout << "mod6: " << mod6 << std::endl; + INFO ("mod2: " << mod2 ); + INFO ("mod6: " << mod6 ); + CHECK_THROWS_AS ( std::swap ( mod2, mod6 ), int ); + INFO ("mod2: " << mod2 ); + INFO ("mod6: " << mod6 ); + CHECK_THROWS_AS ( swap ( mod2, mod6 ), int ); + INFO ("mod2: " << mod2 ); + INFO ("mod6: " << mod6 ); - CPPUNIT_ASSERT_NO_THROW ( mod2.insert ( mod6.begin ( ), mod6.end ( ) ) ); - CPPUNIT_ASSERT_THROW ( mod2.insert ( { 8, 9 } ), int ); + CHECK_NOTHROW ( mod2.insert ( mod6.begin ( ), mod6.end ( ) ) ); + CHECK_THROWS_AS ( mod2.insert ( { 8, 9 } ), int ); - std::cout << "mod2: " << mod2 << std::endl; - std::cout << "mod6: " << mod6 << std::endl; + INFO ("mod2: " << mod2 ); + INFO ("mod6: " << mod6 ); - mod2 = { 4, 6, 8 }; + mod2 = { 4, 6, 8 }; + } } diff --git a/alib2std/test-src/extensions/container/managed/ManagedLinearSetTest.h b/alib2std/test-src/extensions/container/managed/ManagedLinearSetTest.h deleted file mode 100644 index 03dba93740..0000000000 --- a/alib2std/test-src/extensions/container/managed/ManagedLinearSetTest.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MANAGED_LINEAR_SET_TEST_H_ -#define MANAGED_LINEAR_SET_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class ManagedLinearSetTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( ManagedLinearSetTest ); - CPPUNIT_TEST ( testBasics ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - void setUp ( ); - void tearDown ( ); - - void testBasics ( ); -}; - -#endif // MANAGED_LINEAR_SET_TEST_H_ diff --git a/alib2std/test-src/extensions/container/managed/ManagedValueTest.cpp b/alib2std/test-src/extensions/container/managed/ManagedValueTest.cpp index 33e899938f..6c92c48011 100644 --- a/alib2std/test-src/extensions/container/managed/ManagedValueTest.cpp +++ b/alib2std/test-src/extensions/container/managed/ManagedValueTest.cpp @@ -1,22 +1,13 @@ -#include "ManagedValueTest.h" +#include <catch2/catch.hpp> #include <exception> #include <alib/managed_value> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION ( ManagedValueTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION ( ManagedValueTest ); - -void ManagedValueTest::setUp ( ) { -} - -void ManagedValueTest::tearDown ( ) { -} - -void ManagedValueTest::testBasics ( ) { - ext::managed_value < int > number ( 1 ); - number.addChangeCallback ( [ ] ( const int & value ) { if ( value >= 10 ) throw value; } ); - CPPUNIT_ASSERT_NO_THROW ( number = 2 ); - CPPUNIT_ASSERT_THROW ( number = 10, int ); - - +TEST_CASE ( "ManagedValue", "[unit][std][container]" ) { + SECTION ( "Test" ) { + ext::managed_value < int > number ( 1 ); + number.addChangeCallback ( [ ] ( const int & value ) { if ( value >= 10 ) throw value; } ); + CHECK_NOTHROW ( number = 2 ); + CHECK_THROWS_AS ( number = 10, int ); + } } diff --git a/alib2std/test-src/extensions/container/managed/ManagedValueTest.h b/alib2std/test-src/extensions/container/managed/ManagedValueTest.h deleted file mode 100644 index a94f5a1759..0000000000 --- a/alib2std/test-src/extensions/container/managed/ManagedValueTest.h +++ /dev/null @@ -1,18 +0,0 @@ -#ifndef MANAGED_VALUE_TEST_H_ -#define MANAGED_VALUE_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class ManagedValueTest : public CppUnit::TestFixture { - CPPUNIT_TEST_SUITE ( ManagedValueTest ); - CPPUNIT_TEST ( testBasics ); - CPPUNIT_TEST_SUITE_END ( ); - -public: - void setUp ( ); - void tearDown ( ); - - void testBasics ( ); -}; - -#endif // MANAGED_VALUE_TEST_H_ diff --git a/alib2std/test-src/extensions/heaps/HeapsTest.cpp b/alib2std/test-src/extensions/heaps/HeapsTest.cpp index 53a6df9164..95225c3ae8 100644 --- a/alib2std/test-src/extensions/heaps/HeapsTest.cpp +++ b/alib2std/test-src/extensions/heaps/HeapsTest.cpp @@ -1,116 +1,109 @@ -#include "HeapsTest.h" +#include <catch2/catch.hpp> #include <alib/cpp_heap> #include <alib/binomial_heap> #include <alib/fibonacci_heap> -CPPUNIT_TEST_SUITE_NAMED_REGISTRATION( HeapsTest, "bits" ); -CPPUNIT_TEST_SUITE_REGISTRATION( HeapsTest ); - -void HeapsTest::setUp() { -} - -void HeapsTest::tearDown() { -} - -int comparator ( const int & a, const int & b ) { +static int comparator ( const int & a, const int & b ) { return ( b < a ) - ( a < b ); } -int less ( const int & a, const int & b ) { +static int less ( const int & a, const int & b ) { return a < b; } -void HeapsTest::testHeaps ( ) { - alib::BinomialHeap < int > bHeap ( comparator ); - alib::CppHeap < int > cHeap ( less ); - alib::FibonacciHeap < int > fHeap ( comparator ); +TEST_CASE ( "Heaps Test", "[unit][std][bits]" ) { + SECTION ( "Heaps" ) { + alib::BinomialHeap < int > bHeap ( comparator ); + alib::CppHeap < int > cHeap ( less ); + alib::FibonacciHeap < int > fHeap ( comparator ); - auto size = [ & ] ( ) { - int b = bHeap.size ( ); - int c = cHeap.size ( ); - int f = fHeap.size ( ); - CPPUNIT_ASSERT ( b == c && c == f ); - return b; - }; + auto size = [ & ] ( ) { + int b = bHeap.size ( ); + int c = cHeap.size ( ); + int f = fHeap.size ( ); + CHECK ( ( b == c && c == f ) ); + return b; + }; - auto push = [ & ] ( int a ) { - bHeap.insert ( a ); - cHeap.insert ( a ); - fHeap.insert ( a ); - }; + auto push = [ & ] ( int a ) { + bHeap.insert ( a ); + cHeap.insert ( a ); + fHeap.insert ( a ); + }; - auto pop = [ & ] ( ) { - int b = bHeap.extractMax ( ); - int c = cHeap.extractMax ( ); - int f = fHeap.extractMax ( ); - if ( b != c || c != f) { - std::cerr << "??" << std::endl << "size = " << size ( ) << std::endl; - std::cerr << "b = " << b << " c = " << c << " f = " << f << std::endl; - } - CPPUNIT_ASSERT ( b == c ); - CPPUNIT_ASSERT ( c == f ); - return b; - }; + auto pop = [ & ] ( ) { + int b = bHeap.extractMax ( ); + int c = cHeap.extractMax ( ); + int f = fHeap.extractMax ( ); + if ( b != c || c != f) { + INFO ( "??" << "size = " << size ( ) ); + INFO ( "b = " << b << " c = " << c << " f = " << f ); + } + CHECK ( b == c ); + CHECK ( c == f ); + return b; + }; - auto mergeRandom = [ & ] ( unsigned limit ) { - alib::BinomialHeap < int > rbHeap ( comparator ); - alib::CppHeap < int > rcHeap ( comparator ); - alib::FibonacciHeap < int > rfHeap ( comparator ); + auto mergeRandom = [ & ] ( unsigned limit ) { + alib::BinomialHeap < int > rbHeap ( comparator ); + alib::CppHeap < int > rcHeap ( comparator ); + alib::FibonacciHeap < int > rfHeap ( comparator ); - for ( unsigned i = 0; i < limit; ++ i ) { - unsigned val = rand ( ) % 1000; - rbHeap.insert ( val ); - rcHeap.insert ( val ); - rfHeap.insert ( val ); - } + for ( unsigned i = 0; i < limit; ++ i ) { + unsigned val = rand ( ) % 1000; + rbHeap.insert ( val ); + rcHeap.insert ( val ); + rfHeap.insert ( val ); + } - bHeap.mergeWith ( std::move ( rbHeap ) ); - cHeap.mergeWith ( std::move ( rcHeap ) ); - fHeap.mergeWith ( std::move ( rfHeap ) ); - }; + bHeap.mergeWith ( std::move ( rbHeap ) ); + cHeap.mergeWith ( std::move ( rcHeap ) ); + fHeap.mergeWith ( std::move ( rfHeap ) ); + }; - push ( 1 ); - CPPUNIT_ASSERT ( size ( ) == 1 ); - CPPUNIT_ASSERT ( pop ( ) == 1 ); - std::cout << "merge random 50" << std::endl; - mergeRandom ( 50 ); - CPPUNIT_ASSERT ( size ( ) == 50 ); - std::cout << "pop 25" << std::endl; - for ( unsigned i = 0; i < 25; ++ i ) { - std::cout << "pop = " << pop ( ) << std::endl; - } - std::cout << "merge random 50" << std::endl; - mergeRandom ( 50 ); - CPPUNIT_ASSERT ( size ( ) == 75 ); - std::cout << "pop 25" << std::endl; - for ( unsigned i = 0; i < 25; ++ i ) { - std::cout << "pop = " << pop ( ) << std::endl; - } - std::cout << "merge random 50" << std::endl; - mergeRandom ( 50 ); - CPPUNIT_ASSERT ( size ( ) == 100 ); - std::cout << "pop 25" << std::endl; - for ( unsigned i = 0; i < 25; ++ i ) { - std::cout << "pop = " << pop ( ) << std::endl; - } - std::cout << "merge random 50" << std::endl; - mergeRandom ( 50 ); - CPPUNIT_ASSERT ( size ( ) == 125 ); - std::cout << "pop 25" << std::endl; - for ( unsigned i = 0; i < 25; ++ i ) { - std::cout << "pop = " << pop ( ) << std::endl; - } - std::cout << "merge random 50" << std::endl; - mergeRandom ( 50 ); - CPPUNIT_ASSERT ( size ( ) == 150 ); - std::cout << "push random 25" << std::endl; -// fHeap.checkConsystency ( ); - for ( unsigned i = 0; i < 25; ++ i ) { - push ( rand ( ) % 1000 ); - } - std::cout << "pop all" << std::endl; - for ( unsigned i = 0; i < 175; ++ i ) { - std::cout << "pop = " << pop ( ) << std::endl; + push ( 1 ); + CHECK ( size ( ) == 1 ); + CHECK ( pop ( ) == 1 ); + INFO ( "merge random 50" ); + mergeRandom ( 50 ); + CHECK ( size ( ) == 50 ); + INFO ( "pop 25" ); + for ( unsigned i = 0; i < 25; ++ i ) { + INFO ( "pop = " << pop ( ) ); + } + INFO ( "merge random 50" ); + mergeRandom ( 50 ); + CHECK ( size ( ) == 75 ); + INFO ( "pop 25" ); + for ( unsigned i = 0; i < 25; ++ i ) { + INFO ( "pop = " << pop ( ) ); + } + INFO ( "merge random 50" ); + mergeRandom ( 50 ); + CHECK ( size ( ) == 100 ); + INFO ( "pop 25" ); + for ( unsigned i = 0; i < 25; ++ i ) { + INFO ( "pop = " << pop ( ) ); + } + INFO ( "merge random 50" ); + mergeRandom ( 50 ); + CHECK ( size ( ) == 125 ); + INFO ( "pop 25" ); + for ( unsigned i = 0; i < 25; ++ i ) { + INFO ( "pop = " << pop ( ) ); + } + INFO ( "merge random 50" ); + mergeRandom ( 50 ); + CHECK ( size ( ) == 150 ); + INFO ( "push random 25" ); + // fHeap.checkConsystency ( ); + for ( unsigned i = 0; i < 25; ++ i ) { + push ( rand ( ) % 1000 ); + } + INFO ( "pop all" ); + for ( unsigned i = 0; i < 175; ++ i ) { + INFO ( "pop = " << pop ( ) ); + } } } diff --git a/alib2std/test-src/extensions/heaps/HeapsTest.h b/alib2std/test-src/extensions/heaps/HeapsTest.h deleted file mode 100644 index 96a5efaed4..0000000000 --- a/alib2std/test-src/extensions/heaps/HeapsTest.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef HEAPS_TEST_H_ -#define HEAPS_TEST_H_ - -#include <cppunit/extensions/HelperMacros.h> - -class HeapsTest : public CppUnit::TestFixture -{ - CPPUNIT_TEST_SUITE( HeapsTest ); - CPPUNIT_TEST( testHeaps ); - CPPUNIT_TEST_SUITE_END(); - -public: - void setUp(); - void tearDown(); - - void testHeaps(); -}; - -#endif // HEAPS_TEST_H_ diff --git a/alib2std/test-src/main.cpp b/alib2std/test-src/main.cpp index d07f5c9f97..4ed06df1f7 100644 --- a/alib2std/test-src/main.cpp +++ b/alib2std/test-src/main.cpp @@ -1,164 +1,2 @@ -#include <version.hpp> - -#include <tclap/CmdLine.h> - -#include <cppunit/CompilerOutputter.h> -#include <cppunit/extensions/TestFactoryRegistry.h> -#include <cppunit/ui/text/TestRunner.h> -#include <cppunit/TestResultCollector.h> -#include <cppunit/TestResult.h> -#include <cppunit/XmlOutputter.h> - -#include <cppunit/Test.h> -#include <cppunit/TestFailure.h> -#include <cppunit/portability/Stream.h> -#include <cppunit/TestListener.h> -#include <cppunit/SourceLine.h> -#include <cppunit/Exception.h> - -CPPUNIT_NS_BEGIN - -class CPPUNIT_API TestProgressListener : public TestListener -{ -public: - TestProgressListener(); - - virtual ~TestProgressListener(); - - void startTest( Test *test ); - - void addFailure( const TestFailure &failure ); - - void endTest( Test *test ); - - int getResult() const; - - void printResults() const; - -private: - TestProgressListener( const TestProgressListener © ); - - void operator =( const TestProgressListener © ); - -private: - int m_Failures; - int m_Tests; - int m_Assertions; - bool m_lastTestFailed; -}; - -TestProgressListener::TestProgressListener() : m_Failures( 0 ), m_Tests(0), m_Assertions(0), m_lastTestFailed( false ) -{ -} - -TestProgressListener::~TestProgressListener() -{ -} - -void TestProgressListener::startTest( Test * test ) -{ - stdCOut() << test->getName() << ":" << "\n"; - stdCOut().flush(); - - m_lastTestFailed = false; - m_Tests++; -} - -void TestProgressListener::addFailure( const TestFailure &failure ) -{ - stdCOut() << (failure.isError() ? "error" : "assertion") << " : " << failure.failedTestName() << " : " << failure.sourceLine().lineNumber() << "\n"; - stdCOut() << "Exception " << failure.thrownException()->message().details(); - - m_lastTestFailed = true; - if(failure.isError()) m_Failures++; else m_Assertions++; -} - -void TestProgressListener::endTest( Test * test) -{ - stdCOut() << "Result (" << test->getName() << ")"; - stdCOut().flush(); - - if ( !m_lastTestFailed ) - stdCOut() << " : OK"; - else - stdCOut() << " : Fail"; - stdCOut() << "\n\n"; -} - -int TestProgressListener::getResult() const { - return m_Failures + m_Assertions; -} - -void TestProgressListener::printResults() const { - stdCOut() << "Overal result: Tests: " << m_Tests << " Assertions: " << m_Assertions << " Failures: " << m_Failures << "\n"; -} - -CPPUNIT_NS_END - -int main(int argc, char* argv[]) { - try { - TCLAP::CmdLine cmd("Main test binary.", ' ', ALIB_VERSION_INFO); - - TCLAP::MultiArg<std::string> testPathSegments("p", "path", "test path", false, "string" ); - cmd.add( testPathSegments ); - - cmd.parse(argc, argv); - - CppUnit::TestResult controller; - - CppUnit::TestResultCollector result; - controller.addListener( &result ); - - CppUnit::TestProgressListener progressListener; - controller.addListener( &progressListener ); - - CppUnit::Test *suite = NULL; - std::string testPath = ""; - if(testPathSegments.getValue().size() == 0) { - // Get the top level suite from the registry - suite = CppUnit::TestFactoryRegistry::getRegistry().makeTest(); - } else if(testPathSegments.getValue().size() == 1) { - suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest(); - } else { - suite = CppUnit::TestFactoryRegistry::getRegistry(testPathSegments.getValue()[0]).makeTest(); - bool first = true; - for(const std::string& path : testPathSegments.getValue()) { - if(first) { - first = false; - continue; - } - testPath += path + "/"; - } - testPath.pop_back(); - } - - // Adds the test to the list of test to run - CppUnit::TextUi::TestRunner runner; - runner.addTest( suite ); - - // Change the default outputter to a compiler error format outputter - runner.setOutputter( new CppUnit::CompilerOutputter( &runner.result(), std::cerr ) ); - // Run the tests. - runner.run( controller, testPath ); - - progressListener.printResults(); - - std::ofstream xmlFileResults("CppUnitTestResults.xml"); - CppUnit::XmlOutputter xmlOut(&result, xmlFileResults); - xmlOut.write(); - - return progressListener.getResult(); -/* } catch(const exception::AlibException& exception) { - std::cerr << exception.getCause() << std::endl; - return 1;*/ - } catch(const TCLAP::ArgException& exception) { - std::cerr << exception.error() << std::endl; - return 2; - } catch (const std::exception& exception) { - std::cerr << "Exception caught: " << exception.what() << std::endl; - return 3; - } catch(...) { - std::cerr << "Unknown exception caught." << std::endl; - return 127; - } -} +#define CATCH_CONFIG_MAIN +#include <catch2/catch.hpp> -- GitLab