Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Tests for the Bucket Datastructure #27

Merged
Merged
2 changes: 1 addition & 1 deletion include/DataStructures/Container/Queues/Bucket.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ class Bucket {
, TElement
, Types::largeNumber
, Types::largeNumber const *
, Types::largeNumber>;
, Types::largeNumber>; // @TODO deprecated
public:
///@name Constructors and Destructor
///@{
Expand Down
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ add_executable(TestMappingBinaryHeap DataStructures/Container/TestMappingBinaryH
target_link_libraries(TestMappingBinaryHeap EGOA gtest gtest_main gmock_main)
add_test(NAME TestMappingBinaryHeap COMMAND TestMappingBinaryHeap)

# add_executable(TestBucket DataStructures/Container/TestBucket.cpp)
# target_link_libraries(TestBucket EGOA gtest gtest_main gmock_main)
# add_test(NAME TestBucket COMMAND TestBucket)
add_executable(TestBucket DataStructures/Container/TestBucket.cpp)
target_link_libraries(TestBucket EGOA gtest gtest_main gmock_main)
add_test(NAME TestBucket COMMAND TestBucket)

####################################################################################
# Tests for GRAPH data structures ##################################################
Expand Down
107 changes: 50 additions & 57 deletions tests/DataStructures/Container/TestBucket.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace egoa::test {
, "Bucket"
, "Top"
, "!EmptyQueue\\(\\)");
ASSERT_DEATH ( {bucket_.Top();}, "(.*)" );
ASSERT_DEATH ( {bucket_.Top();}, ".*" );
}
#else
#ifdef EGOA_ENABLE_EXCEPTION_HANDLING
Expand Down Expand Up @@ -74,7 +74,7 @@ namespace egoa::test {
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator<"
, "operator.*<"
, "!EmptyQueue\\(\\)");
ASSERT_DEATH ( { auto test = bucket_ < bucketToCompare_;}, assertionString );
}
Expand All @@ -86,7 +86,7 @@ namespace egoa::test {
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator<"
, "operator.*<"
, "!EmptyQueue\\(\\)");
try {
auto test = bucket_ < bucketToCompare_;
Expand All @@ -109,7 +109,7 @@ namespace egoa::test {
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator<="
, "operator.*<="
, "!EmptyQueue\\(\\)");
ASSERT_DEATH ( { auto test = bucket_ <= bucketToCompare_;}, assertionString );
}
Expand All @@ -121,7 +121,7 @@ namespace egoa::test {
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator<="
, "operator.*<="
, "!EmptyQueue\\(\\)");
try {
auto test = bucket_ <= bucketToCompare_;
Expand All @@ -144,7 +144,7 @@ namespace egoa::test {
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator>"
, "operator.*>"
, "!EmptyQueue\\(\\)");
ASSERT_DEATH ( { auto test = bucket_ > bucketToCompare_;}, assertionString );
}
Expand All @@ -156,7 +156,7 @@ namespace egoa::test {
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator>"
, "operator.*>"
, "!EmptyQueue\\(\\)");
try {
auto test = bucket_ > bucketToCompare_;
Expand All @@ -179,7 +179,7 @@ namespace egoa::test {
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator>="
, "operator.*>="
, "!EmptyQueue\\(\\)");
ASSERT_DEATH ( { auto test = bucket_ >= bucketToCompare_;}, assertionString );
}
Expand All @@ -191,7 +191,7 @@ namespace egoa::test {
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator>="
, "operator.*>="
, "!EmptyQueue\\(\\)");
try {
auto test = bucket_ >= bucketToCompare_;
Expand Down Expand Up @@ -342,7 +342,7 @@ TEST_F ( TestBucketWithZeroElements
{
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator\\[\\]"
, "operator.*\\[\\]"
, "HasElementAt\\(index\\)");
ASSERT_DEATH ( {bucket_[0];}, assertionString );
ASSERT_DEATH ( {bucket_[1];}, assertionString );
Expand All @@ -351,34 +351,34 @@ TEST_F ( TestBucketWithZeroElements
#else
#ifdef EGOA_ENABLE_EXCEPTION_HANDLING
TEST_F ( TestBucketWithZeroElements
, AccessElementWithBracketOperatorExceptionHandling )
, AccessElementWithBracketOperatorExceptionHandling )
{
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator\\[\\]"
, "Bucket"
, "operator.*\\[\\]"
, "HasElementAt\\(index\\)");
try {
try {
bucket_[0];
} catch ( std::runtime_error const & error )
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
}
try {
bucket_[1];
} catch ( std::runtime_error const & error )
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
}
try {
bucket_[-1];
} catch ( std::runtime_error const & error )
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
}
} catch ( ... )
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
FAIL() << "Expected std::runtime_error with message: "
<< assertionString;
}
}
Expand Down Expand Up @@ -686,7 +686,7 @@ TEST_F ( TestBucketWithZeroElements
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator<"
, "operator.*<"
, "!rhs.EmptyQueue\\(\\)" );
ASSERT_DEATH ( { auto test = bucket_ < bucketToCompare_;}, assertionString );
}
Expand All @@ -698,7 +698,7 @@ TEST_F ( TestBucketWithZeroElements
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator<"
, "operator.*<"
, "!rhs.EmptyQueue\\(\\)" );
try {
auto test = bucket_ < bucketToCompare_;
Expand All @@ -725,7 +725,7 @@ TEST_F ( TestBucketWithZeroElements
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator<="
, "operator.*<="
, "!rhs.EmptyQueue\\(\\)" );
ASSERT_DEATH ( { auto test = bucket_ <= bucketToCompare_;}, assertionString );
}
Expand All @@ -737,7 +737,7 @@ TEST_F ( TestBucketWithZeroElements
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator<="
, "operator.*<="
, "!rhs.EmptyQueue\\(\\)" );
try {
auto test = bucket_ <= bucketToCompare_;
Expand All @@ -762,7 +762,7 @@ TEST_F ( TestBucketWithZeroElements
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator>"
, "operator.*>"
, "!rhs.EmptyQueue\\(\\)" );
ASSERT_DEATH ( { auto test = bucket_ > bucketToCompare_;}
, assertionString );
Expand All @@ -775,14 +775,13 @@ TEST_F ( TestBucketWithZeroElements
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator>"
, "operator.*>"
, "!rhs.EmptyQueue\\(\\)" );
try {
auto test = bucket_ > bucketToCompare_;
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( MatchesRegex( assertionString.c_str() )
, error.what() );
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
Expand All @@ -804,7 +803,7 @@ TEST_F ( TestBucketWithZeroElements

auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator>="
, "operator.*>="
, "!rhs.EmptyQueue\\(\\)");
ASSERT_DEATH ( { auto test = bucket_ >= bucketToCompare_;}
, assertionString );
Expand All @@ -817,14 +816,13 @@ TEST_F ( TestBucketWithZeroElements
TBucket bucketToCompare_;
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator>="
, "operator.*>="
, "!rhs.EmptyQueue\\(\\)");
try {
auto test = bucket_ >= bucketToCompare_;
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( MatchesRegex( assertionString.c_str() )
, error.what() );
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
Expand Down Expand Up @@ -918,7 +916,7 @@ TEST_F ( TestBucketWithMultipleInteger
::testing::FLAGS_gtest_death_test_style = "threadsafe";

auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "Bucket"
, "ElementAt"
, "HasElementAt\\(index\\)" );

Expand All @@ -934,7 +932,7 @@ TEST_F ( TestBucketWithMultipleInteger
EXPECT_TRUE ( bucket_.EmptyQueue() );

auto assertionString2 = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "Bucket"
, "Pop"
, "!EmptyQueue\\(\\)" );
ASSERT_DEATH ( {bucket_.Pop();}, assertionString2 );
Expand All @@ -945,7 +943,7 @@ TEST_F ( TestBucketWithMultipleInteger
, AccessElementElementAtExceptionHandling )
{
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "Bucket"
, "ElementAt"
, "HasElementAt\\(index\\)" );
try {
Expand Down Expand Up @@ -976,19 +974,18 @@ TEST_F ( TestBucketWithMultipleInteger
EXPECT_TRUE ( bucket_.EmptyQueue() );

auto assertionString2 = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "Bucket"
, "Pop"
, "!EmptyQueue\\(\\)" );
try {
bucket_.Pop();
} catch ( std::runtime_error const & error )
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( MatchesRegex( assertionString2.c_str() )
, error.what() );
EXPECT_THAT ( error.what(), MatchesRegex( assertionString2.c_str() ) );
}
} catch ( ... )
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
FAIL() << "Expected std::runtime_error with message: "
<< assertionString;
}
}
Expand All @@ -997,15 +994,15 @@ TEST_F ( TestBucketWithMultipleInteger

#ifdef EGOA_ENABLE_ASSERTION
TEST_F ( TestBucketWithMultipleIntegerDeathTest
, AccessElementWithBracketOperatorDeathTest )
, AccessElementWithBracketOperatorDeathTest )
{
// For more details see
// https://gitlab.inria.fr/Phylophile/Treerecs/blob/f6551e06797b52819ba3e630b92315254a944da5/tests/gtest/googletest/docs/AdvancedGuide.md
::testing::FLAGS_gtest_death_test_style = "threadsafe";

auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator\\[\\]"
, "operator.*\\[\\]"
, "HasElementAt\\(index\\)" );

ASSERT_DEATH ( { bucket_[0]; }, assertionString );
Expand All @@ -1015,36 +1012,34 @@ TEST_F ( TestBucketWithMultipleInteger
#else
#ifdef EGOA_ENABLE_EXCEPTION_HANDLING
TEST_F ( TestBucketWithMultipleInteger
, AccessElementWithBracketOperatorExceptionHandling )
, AccessElementWithBracketOperatorExceptionHandling )
{
auto assertionString = buildAssertionString ( "Bucket.hpp"
, "Bucket"
, "operator\\[\\]"
, "operator.*\\[\\]"
, "HasElementAt\\(index\\)" );
try {
try {
bucket_[0];
} catch ( std::runtime_error const & error )
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
}
try {
bucket_[1];
} catch ( std::runtime_error const & error )
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( MatchesRegex( assertionString.c_str() )
, error.what() );
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
}
try {
bucket_[-1];
} catch ( std::runtime_error const & error )
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( MatchesRegex( assertionString.c_str() )
, error.what() );
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
}
} catch ( ... )
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
FAIL() << "Expected std::runtime_error with message: "
<< assertionString;
}
}
Expand Down Expand Up @@ -1126,8 +1121,7 @@ TEST_F ( TestBucketWithMultipleInteger
bucket_.Pop();
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( MatchesRegex( assertionString.c_str() )
, error.what() );
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
Expand Down Expand Up @@ -1194,8 +1188,7 @@ TEST_F ( TestBucketWithMultipleInteger
bucket_.DeleteTop();
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( MatchesRegex( assertionString.c_str() )
, error.what() );
EXPECT_THAT ( error.what(), MatchesRegex( assertionString.c_str() ) );
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
Expand Down Expand Up @@ -1705,4 +1698,4 @@ TEST_F ( TestBucketWithMultipleInteger
/// @todo tests for breakable for_all_optima
///@}

} // namespace egoa::test
} // namespace egoa::test