From 317b051cfd3cfbd86b99e175b50b13290c26d0ea Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Wed, 9 Oct 2024 17:40:03 -0600 Subject: [PATCH] Updating test to include ctor and assignment oepartor tests for object that used placement new --- .../test/ReactionMultiplicities.test.cpp | 210 ++++++++++++++++++ .../test/ReactionCrossSections.test.cpp | 108 +++++++++ .../test/ScatteringMatrix.test.cpp | 210 ++++++++++++++++++ 3 files changed, 528 insertions(+) diff --git a/src/NDItk/depletion/ReactionMultiplicities/test/ReactionMultiplicities.test.cpp b/src/NDItk/depletion/ReactionMultiplicities/test/ReactionMultiplicities.test.cpp index a29051a..939b7c3 100644 --- a/src/NDItk/depletion/ReactionMultiplicities/test/ReactionMultiplicities.test.cpp +++ b/src/NDItk/depletion/ReactionMultiplicities/test/ReactionMultiplicities.test.cpp @@ -19,6 +19,7 @@ void verifyChunk( const ReactionMultiplicities& ); std::string chunkWithMultiplicityType(); void verifyChunkWithMultiplicityType( const ReactionMultiplicities& ); std::string chunkWithInsufficientNumberReactions(); +ReactionMultiplicities makeDummyRecord(); SCENARIO( "ReactionMultiplicities" ) { @@ -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" ) { @@ -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" ) { @@ -302,3 +507,8 @@ std::string chunkWithInsufficientNumberReactions() { return "rprod\n"; } + +ReactionMultiplicities makeDummyRecord() { + + return ReactionMultiplicities( { { 102, { 1 }, { 1 } } } ); +} diff --git a/src/NDItk/multigroup/ReactionCrossSections/test/ReactionCrossSections.test.cpp b/src/NDItk/multigroup/ReactionCrossSections/test/ReactionCrossSections.test.cpp index c6dd7bd..5704065 100644 --- a/src/NDItk/multigroup/ReactionCrossSections/test/ReactionCrossSections.test.cpp +++ b/src/NDItk/multigroup/ReactionCrossSections/test/ReactionCrossSections.test.cpp @@ -17,6 +17,7 @@ std::string chunk(); void verifyChunk( const ReactionCrossSections& ); std::string chunkWithInsufficientNumberReactions(); std::string chunkWithInsufficientNumberCrossSectionValues(); +ReactionCrossSections makeDummyRecord(); SCENARIO( "ReactionCrossSections" ) { @@ -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" ) { @@ -228,3 +331,8 @@ std::string chunkWithInsufficientNumberCrossSectionValues() { " 2 0\n" " 16 1.1234567\n"; } + +ReactionCrossSections makeDummyRecord() { + + return ReactionCrossSections( { { 18, 200.0, { 10., 20. } } } ); +} diff --git a/src/NDItk/multigroup/ScatteringMatrix/test/ScatteringMatrix.test.cpp b/src/NDItk/multigroup/ScatteringMatrix/test/ScatteringMatrix.test.cpp index cda24cf..504c28c 100644 --- a/src/NDItk/multigroup/ScatteringMatrix/test/ScatteringMatrix.test.cpp +++ b/src/NDItk/multigroup/ScatteringMatrix/test/ScatteringMatrix.test.cpp @@ -17,6 +17,7 @@ std::string chunk(); void verifyChunk( const ScatteringMatrix& ); std::string chunkForProductionMatrix(); void verifyChunkForProductionMatrix( const ScatteringMatrix& ); +ScatteringMatrix makeDummyRecord(); SCENARIO( "ScatteringMatrix" ) { @@ -73,6 +74,108 @@ SCENARIO( "ScatteringMatrix" ) { CHECK( buffer == record ); } // THEN } // WHEN + + WHEN( "using the copy constructor" ) { + + auto iter = record.begin() + 7; + auto end = record.end(); + ScatteringMatrix chunk; + chunk.read( iter, end, 3, 2 ); + + ScatteringMatrix copy( chunk ); + + THEN( "a ScatteringMatrix 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() + 7; + auto end = record.end(); + ScatteringMatrix chunk; + chunk.read( iter, end, 3, 2 ); + + ScatteringMatrix move( std::move( chunk ) ); + + THEN( "a ScatteringMatrix 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() + 7; + auto end = record.end(); + ScatteringMatrix chunk; + chunk.read( iter, end, 3, 2 ); + + ScatteringMatrix copy = makeDummyRecord(); + copy = chunk; + + THEN( "a ScatteringMatrix 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() + 7; + auto end = record.end(); + ScatteringMatrix chunk; + chunk.read( iter, end, 3, 2 ); + + ScatteringMatrix move = makeDummyRecord(); + move = std::move( chunk ); + + THEN( "a ScatteringMatrix 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 ScatteringMatrix instance for a secondary particle" ) { @@ -128,6 +231,108 @@ SCENARIO( "ScatteringMatrix" ) { CHECK( buffer == record ); } // THEN } // WHEN + + WHEN( "using the copy constructor" ) { + + auto iter = record.begin() + 17; + auto end = record.end(); + ScatteringMatrix chunk( 1001 ); + chunk.read( iter, end, 3, 2, 2 ); + + ScatteringMatrix copy( chunk ); + + THEN( "a ScatteringMatrix can be constructed and members can " + "be tested" ) { + + verifyChunkForProductionMatrix( 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() + 17; + auto end = record.end(); + ScatteringMatrix chunk( 1001 ); + chunk.read( iter, end, 3, 2, 2 ); + + ScatteringMatrix move( std::move( chunk ) ); + + THEN( "a ScatteringMatrix can be constructed and members can " + "be tested" ) { + + verifyChunkForProductionMatrix( 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() + 17; + auto end = record.end(); + ScatteringMatrix chunk( 1001 ); + chunk.read( iter, end, 3, 2, 2 ); + + ScatteringMatrix copy = makeDummyRecord(); + copy = chunk; + + THEN( "a ScatteringMatrix can be copy assigned and " + "members can be tested" ) { + + verifyChunkForProductionMatrix( 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() + 17; + auto end = record.end(); + ScatteringMatrix chunk( 1001 ); + chunk.read( iter, end, 3, 2, 2 ); + + ScatteringMatrix move = makeDummyRecord(); + move = std::move( chunk ); + + THEN( "a ScatteringMatrix can be copy assigned and " + "members can be tested" ) { + + verifyChunkForProductionMatrix( 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 ScatteringMatrix instance" ) { @@ -335,3 +540,8 @@ void verifyChunkForProductionMatrix( const ScatteringMatrix& chunk ) { CHECK_THAT( 15, WithinRel( moment.matrix()[2][0] ) ); CHECK_THAT( 16, WithinRel( moment.matrix()[2][1] ) ); } + +ScatteringMatrix makeDummyRecord() { + + return { { { 0, { 1, 2, 3, 4 }, 2 } } }; +}