Skip to content

Commit

Permalink
Updating test to include ctor and assignment oepartor tests for objec…
Browse files Browse the repository at this point in the history
…t that used placement new
  • Loading branch information
whaeck committed Oct 9, 2024
1 parent 98dd512 commit 317b051
Show file tree
Hide file tree
Showing 3 changed files with 528 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ void verifyChunk( const ReactionMultiplicities& );
std::string chunkWithMultiplicityType();
void verifyChunkWithMultiplicityType( const ReactionMultiplicities& );
std::string chunkWithInsufficientNumberReactions();
ReactionMultiplicities makeDummyRecord();

SCENARIO( "ReactionMultiplicities" ) {

Expand Down Expand Up @@ -75,6 +76,108 @@ SCENARIO( "ReactionMultiplicities" ) {
CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using the copy constructor" ) {

auto iter = record.begin() + 5;
auto end = record.end();
ReactionMultiplicities chunk;
chunk.read( iter, end, 2 );

ReactionMultiplicities copy( chunk );

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

verifyChunk( copy );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using the move constructor" ) {

auto iter = record.begin() + 5;
auto end = record.end();
ReactionMultiplicities chunk;
chunk.read( iter, end, 2 );

ReactionMultiplicities move( std::move( chunk ) );

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

verifyChunk( move );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using copy assignment" ) {

auto iter = record.begin() + 5;
auto end = record.end();
ReactionMultiplicities chunk;
chunk.read( iter, end, 2 );

ReactionMultiplicities copy = makeDummyRecord();
copy = chunk;

THEN( "an ReactionMultiplicities can be copy assigned and "
"members can be tested" ) {

verifyChunk( copy );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using move assignment" ) {

auto iter = record.begin() + 5;
auto end = record.end();
ReactionMultiplicities chunk;
chunk.read( iter, end, 2 );

ReactionMultiplicities move = makeDummyRecord();
move = std::move( chunk );

THEN( "an ReactionMultiplicities can be copy assigned and "
"members can be tested" ) {

verifyChunk( move );
} // THEN

THEN( "the record can be printed" ) {

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

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

GIVEN( "valid data for a ReactionMultiplicities instance with a multiplicity type" ) {
Expand Down Expand Up @@ -131,6 +234,108 @@ SCENARIO( "ReactionMultiplicities" ) {
CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using the copy constructor" ) {

auto iter = record.begin() + 9;
auto end = record.end();
ReactionMultiplicities chunk( ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

ReactionMultiplicities copy( chunk );

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

verifyChunkWithMultiplicityType( copy );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using the move constructor" ) {

auto iter = record.begin() + 9;
auto end = record.end();
ReactionMultiplicities chunk( ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

ReactionMultiplicities move( std::move( chunk ) );

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

verifyChunkWithMultiplicityType( move );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using copy assignment" ) {

auto iter = record.begin() + 9;
auto end = record.end();
ReactionMultiplicities chunk( ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

ReactionMultiplicities copy = makeDummyRecord();
copy = chunk;

THEN( "an ReactionMultiplicities can be copy assigned and "
"members can be tested" ) {

verifyChunkWithMultiplicityType( copy );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using move assignment" ) {

auto iter = record.begin() + 9;
auto end = record.end();
ReactionMultiplicities chunk( ReactionMultiplicityType::All );
chunk.read( iter, end, 2 );

ReactionMultiplicities move = makeDummyRecord();
move = std::move( chunk );

THEN( "an ReactionMultiplicities can be copy assigned and "
"members can be tested" ) {

verifyChunkWithMultiplicityType( move );
} // THEN

THEN( "the record can be printed" ) {

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

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

GIVEN( "invalid data for a ReactionMultiplicities instance" ) {
Expand Down Expand Up @@ -302,3 +507,8 @@ std::string chunkWithInsufficientNumberReactions() {

return "rprod\n";
}

ReactionMultiplicities makeDummyRecord() {

return ReactionMultiplicities( { { 102, { 1 }, { 1 } } } );
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ std::string chunk();
void verifyChunk( const ReactionCrossSections& );
std::string chunkWithInsufficientNumberReactions();
std::string chunkWithInsufficientNumberCrossSectionValues();
ReactionCrossSections makeDummyRecord();

SCENARIO( "ReactionCrossSections" ) {

Expand Down Expand Up @@ -73,6 +74,108 @@ SCENARIO( "ReactionCrossSections" ) {
CHECK( buffer == record );
} // THEN
} // WHEN

WHEN( "using the copy constructor" ) {

auto iter = record.begin() + 8;
auto end = record.end();
ReactionCrossSections chunk;
chunk.read( iter, end, 2, 7 );

ReactionCrossSections copy( chunk );

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

verifyChunk( copy );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using the move constructor" ) {

auto iter = record.begin() + 8;
auto end = record.end();
ReactionCrossSections chunk;
chunk.read( iter, end, 2, 7 );

ReactionCrossSections move( std::move( chunk ) );

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

verifyChunk( move );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using copy assignment" ) {

auto iter = record.begin() + 8;
auto end = record.end();
ReactionCrossSections chunk;
chunk.read( iter, end, 2, 7 );

ReactionCrossSections copy = makeDummyRecord();
copy = chunk;

THEN( "a ReactionCrossSections can be copy assigned and "
"members can be tested" ) {

verifyChunk( copy );
} // THEN

THEN( "the record can be printed" ) {

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

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

WHEN( "using move assignment" ) {

auto iter = record.begin() + 8;
auto end = record.end();
ReactionCrossSections chunk;
chunk.read( iter, end, 2, 7 );

ReactionCrossSections move = makeDummyRecord();
move = std::move( chunk );

THEN( "a ReactionCrossSections can be copy assigned and "
"members can be tested" ) {

verifyChunk( move );
} // THEN

THEN( "the record can be printed" ) {

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

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

GIVEN( "invalid data for a ReactionCrossSections instance" ) {
Expand Down Expand Up @@ -228,3 +331,8 @@ std::string chunkWithInsufficientNumberCrossSectionValues() {
" 2 0\n"
" 16 1.1234567\n";
}

ReactionCrossSections makeDummyRecord() {

return ReactionCrossSections( { { 18, 200.0, { 10., 20. } } } );
}
Loading

0 comments on commit 317b051

Please sign in to comment.