Skip to content

Commit

Permalink
Adding test for incoherent data
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Aug 12, 2024
1 parent 0082273 commit ce25e43
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 8 deletions.
1 change: 1 addition & 0 deletions cmake/unit_testing.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ add_subdirectory( src/dryad/TabulatedEnergyDistribution/test )
add_subdirectory( src/dryad/TabulatedEnergyDistributions/test )
add_subdirectory( src/dryad/TwoBodyDistributionData/test )
add_subdirectory( src/dryad/UncorrelatedDistributionData/test )
add_subdirectory( src/dryad/IncoherentDistributionData/test )
add_subdirectory( src/dryad/ReactionProduct/test )

add_subdirectory( src/dryad/TabulatedCrossSection/test )
Expand Down
1 change: 1 addition & 0 deletions src/dryad/IncoherentDistributionData/test/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
add_cpp_test( IncoherentDistributionData IncoherentDistributionData.test.cpp )
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// include Catch2
#include <catch2/catch_test_macros.hpp>
#include <catch2/matchers/catch_matchers_floating_point.hpp>
using Catch::Matchers::WithinRel;

// what we are testing
#include "dryad/IncoherentDistributionData.hpp"

// other includes

// convenience typedefs
using namespace njoy::dryad;

void verifyChunk( const IncoherentDistributionData& );

SCENARIO( "IncoherentDistributionData" ) {

GIVEN( "valid data for incoherent distribution data" ) {

WHEN( "the data is given explicitly" ) {

ReferenceFrame frame = ReferenceFrame::CentreOfMass;
TabulatedScatteringFunction scattering( { 1., 2e+7 }, { 2., 1. } );

IncoherentDistributionData chunk( std::move( frame ), std::move( scattering ) );

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

verifyChunk( chunk );
} // THEN
} // WHEN
} // GIVEN
} // SCENARIO

void verifyChunk( const IncoherentDistributionData& chunk ) {

CHECK( DistributionDataType::Incoherent == chunk.type() );
CHECK( ReferenceFrame::CentreOfMass == chunk.frame() );

CHECK_THAT( 1. , WithinRel( chunk.scatteringFunction().lowerInverseLengthLimit() ) );
CHECK_THAT( 2e+7, WithinRel( chunk.scatteringFunction().upperInverseLengthLimit() ) );
CHECK( 2 == chunk.scatteringFunction().inverseLengths().size() );
CHECK( 2 == chunk.scatteringFunction().values().size() );
CHECK( 1 == chunk.scatteringFunction().boundaries().size() );
CHECK( 1 == chunk.scatteringFunction().interpolants().size() );
CHECK_THAT( 1. , WithinRel( chunk.scatteringFunction().inverseLengths()[0] ) );
CHECK_THAT( 2e+7, WithinRel( chunk.scatteringFunction().inverseLengths()[1] ) );
CHECK_THAT( 2., WithinRel( chunk.scatteringFunction().values()[0] ) );
CHECK_THAT( 1., WithinRel( chunk.scatteringFunction().values()[1] ) );
CHECK( 1 == chunk.scatteringFunction().boundaries()[0] );
CHECK( InterpolationType::LinearLinear == chunk.scatteringFunction().interpolants()[0] );
CHECK( true == chunk.scatteringFunction().isLinearised() );
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ SCENARIO( "TabulatedScatteringFunction" ) {

WHEN( "the data is given explicitly" ) {

const std::vector< double > energies = { 1., 2., 3., 4. };
const std::vector< double > x = { 1., 2., 3., 4. };
const std::vector< double > values = { 4., 3., 2., 1. };

TabulatedScatteringFunction chunk( std::move( energies ), std::move( values ) );
TabulatedScatteringFunction chunk( std::move( x ), std::move( values ) );

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

Expand Down Expand Up @@ -621,11 +621,11 @@ SCENARIO( "TabulatedScatteringFunction" ) {

WHEN( "the data is given explicitly" ) {

const std::vector< double > energies = { 1., 2., 2., 3., 4. };
const std::vector< double > x = { 1., 2., 2., 3., 4. };
const std::vector< double > values = { 4., 3., 4., 3., 2. };
InterpolationType interpolant = InterpolationType::LinearLinear;

TabulatedScatteringFunction chunk( std::move( energies ), std::move( values ),
TabulatedScatteringFunction chunk( std::move( x ), std::move( values ),
interpolant );

THEN( "a TabulatedScatteringFunction can be constructed and members can be tested" ) {
Expand Down Expand Up @@ -1289,7 +1289,7 @@ SCENARIO( "TabulatedScatteringFunction" ) {

WHEN( "the data is given explicitly" ) {

const std::vector< double > energies = { 1., 2., 3., 4. };
const std::vector< double > x = { 1., 2., 3., 4. };
const std::vector< double > values = { 4., 3., 2., 1. };
const std::vector< std::size_t > boundaries = { 1, 3 };
const std::vector< InterpolationType > interpolants = {
Expand All @@ -1298,7 +1298,7 @@ SCENARIO( "TabulatedScatteringFunction" ) {
InterpolationType::LinearLog
};

TabulatedScatteringFunction chunk( std::move( energies ),
TabulatedScatteringFunction chunk( std::move( x ),
std::move( values ),
std::move( boundaries ),
std::move( interpolants ) );
Expand Down Expand Up @@ -1437,7 +1437,7 @@ SCENARIO( "TabulatedScatteringFunction" ) {

WHEN( "the data is given explicitly" ) {

const std::vector< double > energies = { 1., 2., 2., 3., 4. };
const std::vector< double > x = { 1., 2., 2., 3., 4. };
const std::vector< double > values = { 4., 3., 4., 3., 2. };
const std::vector< std::size_t > boundaries = { 1, 4 };
const std::vector< InterpolationType > interpolants = {
Expand All @@ -1446,7 +1446,7 @@ SCENARIO( "TabulatedScatteringFunction" ) {
InterpolationType::LinearLog
};

TabulatedScatteringFunction chunk( std::move( energies ),
TabulatedScatteringFunction chunk( std::move( x ),
std::move( values ),
std::move( boundaries ),
std::move( interpolants ) );
Expand Down

0 comments on commit ce25e43

Please sign in to comment.