Skip to content

Commit

Permalink
Activate DynamicGraph Datastructure Tests (#52)
Browse files Browse the repository at this point in the history
* Activate DynamicGraph tests
* Fix the death test error
* Add missing namespace ::testing::MatchesRegex
  • Loading branch information
franziska-wegner authored Dec 26, 2023
1 parent 9fb0083 commit fe424e7
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
6 changes: 3 additions & 3 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ add_executable(TestGraph DataStructures/Graphs/TestGraph.cpp)
target_link_libraries(TestGraph EGOA ${GUROBI_LIBRARIES} gtest gtest_main gmock_main)
add_test(NAME TestGraph COMMAND TestGraph)

# add_executable(TestDynamicGraph DataStructures/Graphs/TestDynamicGraph.cpp)
# target_link_libraries(TestDynamicGraph EGOA ${GUROBI_LIBRARIES} gtest gtest_main gmock_main)
# add_test(NAME TestDynamicGraph COMMAND TestDynamicGraph)
add_executable(TestDynamicGraph DataStructures/Graphs/TestDynamicGraph.cpp)
target_link_libraries(TestDynamicGraph EGOA ${GUROBI_LIBRARIES} gtest gtest_main gmock_main)
add_test(NAME TestDynamicGraph COMMAND TestDynamicGraph)

# add_executable(TestPowerGrid DataStructures/Graphs/TestPowerGrid.cpp)
# target_link_libraries(TestPowerGrid EGOA ${GUROBI_LIBRARIES} gtest gtest_main gmock_main)
Expand Down
35 changes: 29 additions & 6 deletions tests/DataStructures/Graphs/TestDynamicGraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,39 @@

#include "TestDynamicGraph.hpp"

using ::testing::MatchesRegex;

namespace egoa::test {

#pragma mark DeleteVertex

TEST_F(TestDynamicGraphEmptyDeathTest, DeleteVertex) {
auto assertionMessage =
this->assertionString("RemoveVertexAt", "VertexExists\\(id\\)");
Types::vertexId id = 0;
EXPECT_DEATH( { this->graph_.RemoveVertexAt(id); }, assertionMessage);
}
#ifdef EGOA_ENABLE_ASSERTION
TEST_F(TestDynamicGraphEmptyDeathTest, DeleteVertex) {
auto assertionMessage =
this->assertionString("RemoveVertexAt", "VertexExists\\(id\\)");
Types::vertexId id = 0;
EXPECT_DEATH( { this->graph_.RemoveVertexAt(id); }, assertionMessage);
}
#else
#ifdef EGOA_ENABLE_EXCEPTION_HANDLING
TEST_F ( TestDynamicGraphEmpty
, DeleteVertexExceptionHandling )
{
auto assertionString = this->assertionString("RemoveVertexAt", "VertexExists\\(id\\)");
Types::vertexId id = 0;
try {
this->graph_.RemoveVertexAt(id);
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( error.what(), MatchesRegex(assertionString.c_str()) );
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
<< assertionString;
}
}
#endif // ifdef EGOA_ENABLE_EXCEPTION_HANDLING
#endif // ifdef EGOA_ENABLE_ASSERTION

TEST_F(TestDynamicGraphSingleVertex, DeleteVertex) {
this->graph_.RemoveVertexAt(this->id_);
Expand Down

0 comments on commit fe424e7

Please sign in to comment.