Skip to content

Commit

Permalink
Adding C++ tests
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Jun 4, 2024
1 parent a76e1e1 commit 67d5371
Showing 1 changed file with 126 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ using ReactionMultiplicities = depletion::ReactionMultiplicities;

std::string chunk();
void verifyChunk( const ReactionMultiplicities& );
std::string chunkWithMultiplicityType();
void verifyChunkWithMultiplicityType( const ReactionMultiplicities& );
std::string chunkWithInsufficientNumberReactions();

SCENARIO( "ReactionMultiplicities" ) {
Expand Down Expand Up @@ -74,6 +76,62 @@ SCENARIO( "ReactionMultiplicities" ) {
} // WHEN
} // GIVEN

GIVEN( "valid data for a ReactionMultiplicities instance with a multiplicity type" ) {

std::string record = chunkWithMultiplicityType();

WHEN( "the data is given explicitly" ) {

std::vector< Multiplicities > multiplicities = {

{ 2, { 1, 92235 }, { 1, 1 } },
{ 16, { 1, 92234 }, { 2, 1 } }
};

ReactionMultiplicities chunk( depletion::ReactionMultiplicityType::All,
std::move( multiplicities ) );

THEN( "a ReactionMultiplicities can be constructed and members can "
"be tested" ) {

verifyChunkWithMultiplicityType( chunk );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
chunk.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "the data is defined using iterators" ) {

auto iter = record.begin() + 9;
auto end = record.end();

ReactionMultiplicities chunk( depletion::ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

THEN( "a ReactionMultiplicities can be constructed and members can "
"be tested" ) {

verifyChunkWithMultiplicityType( chunk );
} // THEN

THEN( "the record can be printed" ) {

std::string buffer;
auto output = std::back_inserter( buffer );
chunk.print( output );

CHECK( buffer == record );
} // THEN
} // WHEN
} // GIVEN

GIVEN( "invalid data for a ReactionMultiplicities instance" ) {

WHEN( "the number of reactions is insufficient" ) {
Expand Down Expand Up @@ -170,6 +228,74 @@ void verifyChunk( const ReactionMultiplicities& chunk ) {
CHECK( 1 == chunk.reaction( 16 ).multiplicities()[1] );
}

std::string chunkWithMultiplicityType() {

return "rprod_all\n"
" 2\n"
" 2\n"
" 1 1\n"
" 92235 1\n"
" 16\n"
" 2\n"
" 1 2\n"
" 92234 1\n";
}

void verifyChunkWithMultiplicityType( const ReactionMultiplicities& chunk ) {

CHECK( "rprod_all" == chunk.keyword() );
CHECK( 2 == chunk.values()[0] );
CHECK( 2 == chunk.values()[1] );
CHECK( 1 == chunk.values()[2] );
CHECK( 1 == chunk.values()[3] );
CHECK( 92235 == chunk.values()[4] );
CHECK( 1 == chunk.values()[5] );
CHECK( 16 == chunk.values()[6] );
CHECK( 2 == chunk.values()[7] );
CHECK( 1 == chunk.values()[8] );
CHECK( 2 == chunk.values()[9] );
CHECK( 92234 == chunk.values()[10] );
CHECK( 1 == chunk.values()[11] );

CHECK( false == chunk.empty() );
CHECK( 12 == chunk.size() );

CHECK( 2 == chunk.numberReactions() );

CHECK( true == chunk.hasReaction( 2 ) );
CHECK( true == chunk.hasReaction( 16 ) );
CHECK( false == chunk.hasReaction( 102 ) );

CHECK( 2 == chunk.reactions()[0].identifier() );
CHECK( 2 == chunk.reactions()[0].numberReactionProducts() );
CHECK( 1 == chunk.reactions()[0].reactionProducts()[0] );
CHECK( 92235 == chunk.reactions()[0].reactionProducts()[1] );
CHECK( 1 == chunk.reactions()[0].multiplicities()[0] );
CHECK( 1 == chunk.reactions()[0].multiplicities()[1] );

CHECK( 16 == chunk.reactions()[1].identifier() );
CHECK( 2 == chunk.reactions()[1].numberReactionProducts() );
CHECK( 1 == chunk.reactions()[1].reactionProducts()[0] );
CHECK( 92234 == chunk.reactions()[1].reactionProducts()[1] );
CHECK( 2 == chunk.reactions()[1].multiplicities()[0] );
CHECK( 1 == chunk.reactions()[1].multiplicities()[1] );

auto multiplicities = chunk.reaction( 2 );
CHECK( 2 == chunk.reaction( 2 ).identifier() );
CHECK( 2 == chunk.reaction( 2 ).numberReactionProducts() );
CHECK( 1 == chunk.reaction( 2 ).reactionProducts()[0] );
CHECK( 92235 == chunk.reaction( 2 ).reactionProducts()[1] );
CHECK( 1 == chunk.reaction( 2 ).multiplicities()[0] );
CHECK( 1 == chunk.reaction( 2 ).multiplicities()[1] );

CHECK( 16 == chunk.reaction( 16 ).identifier() );
CHECK( 2 == chunk.reaction( 16 ).numberReactionProducts() );
CHECK( 1 == chunk.reaction( 16 ).reactionProducts()[0] );
CHECK( 92234 == chunk.reaction( 16 ).reactionProducts()[1] );
CHECK( 2 == chunk.reaction( 16 ).multiplicities()[0] );
CHECK( 1 == chunk.reaction( 16 ).multiplicities()[1] );
}

std::string chunkWithInsufficientNumberReactions() {

return "rprod\n";
Expand Down

0 comments on commit 67d5371

Please sign in to comment.