Skip to content

Commit

Permalink
DeathTest Condition for HasGeneratorAt with Exception
Browse files Browse the repository at this point in the history
Changes to be committed:
	modified:   tests/DataStructures/Graphs/TestPowerGrid.cpp
  • Loading branch information
franziska-wegner committed Dec 30, 2023
1 parent 9472a01 commit 4f25c0b
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions tests/DataStructures/Graphs/TestPowerGrid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,7 @@ TEST_F ( TestPowerGridAcm2018MtsfFigure4a
EXPECT_EQ ( 0, network_.NumberOfGenerators() );
}

#ifdef EGOA_ENABLE_ASSERTION
TEST_F ( TestPowerGridAcm2018MtsfFigure4aDeathTest
, RemoveGeneratorAtUsingVertexIdGeneratorId )
{
Expand All @@ -1090,7 +1091,40 @@ TEST_F ( TestPowerGridAcm2018MtsfFigure4aDeathTest
EXPECT_TRUE ( network_.HasGenerator ( static_cast<Types::generatorId>(0) ) );
EXPECT_EQ ( 1, network_.NumberOfGenerators() );
}
#else
#ifdef EGOA_ENABLE_EXCEPTION_HANDLING
TEST_F ( TestPowerGridAcm2018MtsfFigure4a
, RemoveGeneratorAtUsingVertexIdGeneratorIdExceptionHandling )
{
EXPECT_TRUE ( network_.HasGeneratorAt ( static_cast<Types::vertexId>(0) ) );
EXPECT_FALSE ( network_.HasGeneratorAt ( static_cast<Types::vertexId>(1) ) );
EXPECT_TRUE ( network_.HasGenerator ( static_cast<Types::generatorId>(0) ) );
EXPECT_EQ ( 1, network_.NumberOfGenerators() );

// Vertex does not contain the generator, thus method RemoveGeneratorAt access assertion branch
auto assertionString = buildAssertionString ( "PowerGrid.hpp"
, "PowerGrid"
, "RemoveGeneratorAt"
, "false && \"The generatorId does not exist in generatorsAtVertex_\\[vertexId\\]!\"");
try {
network_.RemoveGeneratorAt ( static_cast<Types::vertexId>(1)
, static_cast<Types::generatorId>(0) );
} catch ( std::runtime_error const & error )
{
EXPECT_THAT ( error.what(), MatchesRegex(assertionString.c_str()) );
} catch ( ... )
{
FAIL() << "Expected std::runtime_error with message: "
<< assertionString;
}

EXPECT_TRUE ( network_.HasGenerator ( static_cast<Types::generatorId>(0) ) );
EXPECT_EQ ( 1, network_.NumberOfGenerators() );
}
#endif // ifdef EGOA_ENABLE_EXCEPTION_HANDLING
#endif // ifdef EGOA_ENABLE_ASSERTION

#ifdef EGOA_ENABLE_ASSERTION
TEST_F ( TestPowerGridAcm2018MtsfFigure4aDeathTest
, RemoveGeneratorAtUsingGeneratorIdNonExistingVertexId )
{
Expand Down

0 comments on commit 4f25c0b

Please sign in to comment.