Skip to content

Commit

Permalink
Merge pull request #80 from njoy/fix/assignment
Browse files Browse the repository at this point in the history
Fix/assignment
  • Loading branch information
whaeck authored Sep 24, 2024
2 parents 8c0c3d2 + 3b42e99 commit ecad714
Show file tree
Hide file tree
Showing 18 changed files with 383 additions and 5 deletions.
6 changes: 6 additions & 0 deletions src/scion/math/HistogramTable/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
HistogramTable( const HistogramTable& ) = default;
HistogramTable( HistogramTable&& ) = default;

HistogramTable& operator=( const HistogramTable& ) = default;
HistogramTable& operator=( HistogramTable&& ) = default;

/**
* @brief Constructor
*
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/HistogramTableFunction/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
HistogramTableFunction( const HistogramTableFunction& ) = default;
HistogramTableFunction( HistogramTableFunction&& ) = default;

HistogramTableFunction& operator=( const HistogramTableFunction& ) = default;
HistogramTableFunction& operator=( HistogramTableFunction&& ) = default;

/**
* @brief Constructor
*
Expand Down
14 changes: 12 additions & 2 deletions src/scion/math/InterpolationTable/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ InterpolationTable& operator=( const InterpolationTable& base ) {

if ( this != &base ) {

new (this) InterpolationTable( base );
Parent::operator=( base );
this->x_ = base.x_;
this->y_ = base.y_;
this->boundaries_ = base.boundaries_;
this->interpolants_ = base.interpolants_;
this->generateTables();
}
return *this;
}
Expand All @@ -54,7 +59,12 @@ InterpolationTable& operator=( InterpolationTable&& base ) {

if ( this != &base ) {

new (this) InterpolationTable( std::move( base ) );
Parent::operator=( std::move( base ) );
this->x_ = std::move( base.x_ );
this->y_ = std::move( base.y_ );
this->boundaries_ = std::move( base.boundaries_ );
this->interpolants_ = std::move( base.interpolants_ );
this->generateTables();
}
return *this;
}
Expand Down
90 changes: 90 additions & 0 deletions src/scion/math/InterpolationTable/test/InterpolationTable.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,96 @@ SCENARIO( "InterpolationTable" ) {
CHECK( true == std::holds_alternative< IntervalDomain< double > >( chunk.domain() ) );
} // THEN

THEN( "an InterpolationTable can be copy and move constructed" ) {

InterpolationTable< double > copy( chunk );
CHECK( 4 == copy.numberPoints() );
CHECK( 1 == copy.numberRegions() );
CHECK( 4 == copy.x().size() );
CHECK( 4 == copy.y().size() );
CHECK( 1 == copy.boundaries().size() );
CHECK( 1 == copy.interpolants().size() );
CHECK_THAT( 1., WithinRel( copy.x()[0] ) );
CHECK_THAT( 2., WithinRel( copy.x()[1] ) );
CHECK_THAT( 3., WithinRel( copy.x()[2] ) );
CHECK_THAT( 4., WithinRel( copy.x()[3] ) );
CHECK_THAT( 4., WithinRel( copy.y()[0] ) );
CHECK_THAT( 3., WithinRel( copy.y()[1] ) );
CHECK_THAT( 2., WithinRel( copy.y()[2] ) );
CHECK_THAT( 1., WithinRel( copy.y()[3] ) );
CHECK( 3 == copy.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == copy.interpolants()[0] );
CHECK( true == copy.isLinearised() );
CHECK( true == std::holds_alternative< IntervalDomain< double > >( copy.domain() ) );

InterpolationTable< double > move( std::move( copy ) );
CHECK( 4 == move.numberPoints() );
CHECK( 1 == move.numberRegions() );
CHECK( 4 == move.x().size() );
CHECK( 4 == move.y().size() );
CHECK( 1 == move.boundaries().size() );
CHECK( 1 == move.interpolants().size() );
CHECK_THAT( 1., WithinRel( move.x()[0] ) );
CHECK_THAT( 2., WithinRel( move.x()[1] ) );
CHECK_THAT( 3., WithinRel( move.x()[2] ) );
CHECK_THAT( 4., WithinRel( move.x()[3] ) );
CHECK_THAT( 4., WithinRel( move.y()[0] ) );
CHECK_THAT( 3., WithinRel( move.y()[1] ) );
CHECK_THAT( 2., WithinRel( move.y()[2] ) );
CHECK_THAT( 1., WithinRel( move.y()[3] ) );
CHECK( 3 == move.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == move.interpolants()[0] );
CHECK( true == move.isLinearised() );
CHECK( true == std::holds_alternative< IntervalDomain< double > >( move.domain() ) );
} // THEN

THEN( "an InterpolationTable can be copy and move assigned" ) {

InterpolationTable< double > copy( { 1., 4. }, { 0., 0. } );
copy = chunk;

CHECK( 4 == copy.numberPoints() );
CHECK( 1 == copy.numberRegions() );
CHECK( 4 == copy.x().size() );
CHECK( 4 == copy.y().size() );
CHECK( 1 == copy.boundaries().size() );
CHECK( 1 == copy.interpolants().size() );
CHECK_THAT( 1., WithinRel( copy.x()[0] ) );
CHECK_THAT( 2., WithinRel( copy.x()[1] ) );
CHECK_THAT( 3., WithinRel( copy.x()[2] ) );
CHECK_THAT( 4., WithinRel( copy.x()[3] ) );
CHECK_THAT( 4., WithinRel( copy.y()[0] ) );
CHECK_THAT( 3., WithinRel( copy.y()[1] ) );
CHECK_THAT( 2., WithinRel( copy.y()[2] ) );
CHECK_THAT( 1., WithinRel( copy.y()[3] ) );
CHECK( 3 == copy.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == copy.interpolants()[0] );
CHECK( true == copy.isLinearised() );
CHECK( true == std::holds_alternative< IntervalDomain< double > >( copy.domain() ) );

InterpolationTable< double > move( { 1., 4. }, { 0., 0. } );
move = std::move( copy );

CHECK( 4 == move.numberPoints() );
CHECK( 1 == move.numberRegions() );
CHECK( 4 == move.x().size() );
CHECK( 4 == move.y().size() );
CHECK( 1 == move.boundaries().size() );
CHECK( 1 == move.interpolants().size() );
CHECK_THAT( 1., WithinRel( move.x()[0] ) );
CHECK_THAT( 2., WithinRel( move.x()[1] ) );
CHECK_THAT( 3., WithinRel( move.x()[2] ) );
CHECK_THAT( 4., WithinRel( move.x()[3] ) );
CHECK_THAT( 4., WithinRel( move.y()[0] ) );
CHECK_THAT( 3., WithinRel( move.y()[1] ) );
CHECK_THAT( 2., WithinRel( move.y()[2] ) );
CHECK_THAT( 1., WithinRel( move.y()[3] ) );
CHECK( 3 == move.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == move.interpolants()[0] );
CHECK( true == move.isLinearised() );
CHECK( true == std::holds_alternative< IntervalDomain< double > >( move.domain() ) );
} // THEN

THEN( "an InterpolationTable can be evaluated" ) {

// values of x in the x grid
Expand Down
14 changes: 12 additions & 2 deletions src/scion/math/InterpolationTableFunction/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,12 @@ InterpolationTableFunction& operator=( const InterpolationTableFunction& base )

if ( this != &base ) {

new (this) InterpolationTableFunction( base );
Parent::operator=( base );
this->x_ = base.x_;
this->f_ = base.f_;
this->boundaries_ = base.boundaries_;
this->interpolants_ = base.interpolants_;
this->generateTables();
}
return *this;
}
Expand All @@ -52,7 +57,12 @@ InterpolationTableFunction& operator=( InterpolationTableFunction&& base ) {

if ( this != &base ) {

new (this) InterpolationTableFunction( std::move( base ) );
Parent::operator=( base );
this->x_ = std::move( base.x_ );
this->f_ = std::move( base.f_ );
this->boundaries_ = std::move( base.boundaries_ );
this->interpolants_ = std::move( base.interpolants_ );
this->generateTables();
}
return *this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,191 @@ SCENARIO( "InterpolationTableFunction" ) {
CHECK( InterpolationType::LinearLinear == chunk.interpolants()[0] );
} // THEN

THEN( "an InterpolationTableFunction can be copy and move constructed" ) {

Table2D copy( chunk );
CHECK( 4 == copy.numberPoints() );
CHECK( 1 == copy.numberRegions() );
CHECK( 4 == copy.x().size() );
CHECK( 4 == copy.f().size() );
CHECK( 1 == copy.boundaries().size() );
CHECK( 1 == copy.interpolants().size() );
CHECK_THAT( 1., WithinRel( copy.x()[0] ) );
CHECK_THAT( 2., WithinRel( copy.x()[1] ) );
CHECK_THAT( 3., WithinRel( copy.x()[2] ) );
CHECK_THAT( 4., WithinRel( copy.x()[3] ) );
CHECK( 2 == copy.f()[0].x().size() );
CHECK( 2 == copy.f()[0].y().size() );
CHECK( 3 == copy.f()[1].x().size() );
CHECK( 3 == copy.f()[1].y().size() );
CHECK( 3 == copy.f()[2].x().size() );
CHECK( 3 == copy.f()[2].y().size() );
CHECK( 2 == copy.f()[3].x().size() );
CHECK( 2 == copy.f()[3].y().size() );
CHECK_THAT( -1. , WithinRel( copy.f()[0].x()[0] ) );
CHECK_THAT( 1. , WithinRel( copy.f()[0].x()[1] ) );
CHECK_THAT( 0.5 , WithinRel( copy.f()[0].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( copy.f()[0].y()[1] ) );
CHECK_THAT( -1. , WithinRel( copy.f()[1].x()[0] ) );
CHECK_THAT( 0. , WithinRel( copy.f()[1].x()[1] ) );
CHECK_THAT( 1. , WithinRel( copy.f()[1].x()[2] ) );
CHECK_THAT( 0.49, WithinRel( copy.f()[1].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( copy.f()[1].y()[1] ) );
CHECK_THAT( 0.51, WithinRel( copy.f()[1].y()[2] ) );
CHECK_THAT( -1. , WithinRel( copy.f()[2].x()[0] ) );
CHECK_THAT( 0. , WithinRel( copy.f()[2].x()[1] ) );
CHECK_THAT( 1. , WithinRel( copy.f()[2].x()[2] ) );
CHECK_THAT( 0.4 , WithinRel( copy.f()[2].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( copy.f()[2].y()[1] ) );
CHECK_THAT( 0.6 , WithinRel( copy.f()[2].y()[2] ) );
CHECK_THAT( -1. , WithinRel( copy.f()[3].x()[0] ) );
CHECK_THAT( 1. , WithinRel( copy.f()[3].x()[1] ) );
CHECK_THAT( 0.1 , WithinRel( copy.f()[3].y()[0] ) );
CHECK_THAT( 0.9 , WithinRel( copy.f()[3].y()[1] ) );
CHECK( 3 == copy.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == copy.interpolants()[0] );

Table2D move( std::move( copy ) );
CHECK( 4 == move.numberPoints() );
CHECK( 1 == move.numberRegions() );
CHECK( 4 == move.x().size() );
CHECK( 4 == move.f().size() );
CHECK( 1 == move.boundaries().size() );
CHECK( 1 == move.interpolants().size() );
CHECK_THAT( 1., WithinRel( move.x()[0] ) );
CHECK_THAT( 2., WithinRel( move.x()[1] ) );
CHECK_THAT( 3., WithinRel( move.x()[2] ) );
CHECK_THAT( 4., WithinRel( move.x()[3] ) );
CHECK( 2 == move.f()[0].x().size() );
CHECK( 2 == move.f()[0].y().size() );
CHECK( 3 == move.f()[1].x().size() );
CHECK( 3 == move.f()[1].y().size() );
CHECK( 3 == move.f()[2].x().size() );
CHECK( 3 == move.f()[2].y().size() );
CHECK( 2 == move.f()[3].x().size() );
CHECK( 2 == move.f()[3].y().size() );
CHECK_THAT( -1. , WithinRel( move.f()[0].x()[0] ) );
CHECK_THAT( 1. , WithinRel( move.f()[0].x()[1] ) );
CHECK_THAT( 0.5 , WithinRel( move.f()[0].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( move.f()[0].y()[1] ) );
CHECK_THAT( -1. , WithinRel( move.f()[1].x()[0] ) );
CHECK_THAT( 0. , WithinRel( move.f()[1].x()[1] ) );
CHECK_THAT( 1. , WithinRel( move.f()[1].x()[2] ) );
CHECK_THAT( 0.49, WithinRel( move.f()[1].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( move.f()[1].y()[1] ) );
CHECK_THAT( 0.51, WithinRel( move.f()[1].y()[2] ) );
CHECK_THAT( -1. , WithinRel( move.f()[2].x()[0] ) );
CHECK_THAT( 0. , WithinRel( move.f()[2].x()[1] ) );
CHECK_THAT( 1. , WithinRel( move.f()[2].x()[2] ) );
CHECK_THAT( 0.4 , WithinRel( move.f()[2].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( move.f()[2].y()[1] ) );
CHECK_THAT( 0.6 , WithinRel( move.f()[2].y()[2] ) );
CHECK_THAT( -1. , WithinRel( move.f()[3].x()[0] ) );
CHECK_THAT( 1. , WithinRel( move.f()[3].x()[1] ) );
CHECK_THAT( 0.1 , WithinRel( move.f()[3].y()[0] ) );
CHECK_THAT( 0.9 , WithinRel( move.f()[3].y()[1] ) );
CHECK( 3 == move.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == move.interpolants()[0] );
} // THEN

THEN( "an InterpolationTableFunction can be copy and move assigned" ) {

const std::vector< double > x = { 0., 1. };
const std::vector< InterpolationTable< double > > f = {

{ { -1., +1. }, { 0.5, 0.5 } },
{ { -1., +1. }, { 0.1, 0.9 } }
};

Table2D copy( x, f );
copy = chunk;

CHECK( 4 == copy.numberPoints() );
CHECK( 1 == copy.numberRegions() );
CHECK( 4 == copy.x().size() );
CHECK( 4 == copy.f().size() );
CHECK( 1 == copy.boundaries().size() );
CHECK( 1 == copy.interpolants().size() );
CHECK_THAT( 1., WithinRel( copy.x()[0] ) );
CHECK_THAT( 2., WithinRel( copy.x()[1] ) );
CHECK_THAT( 3., WithinRel( copy.x()[2] ) );
CHECK_THAT( 4., WithinRel( copy.x()[3] ) );
CHECK( 2 == copy.f()[0].x().size() );
CHECK( 2 == copy.f()[0].y().size() );
CHECK( 3 == copy.f()[1].x().size() );
CHECK( 3 == copy.f()[1].y().size() );
CHECK( 3 == copy.f()[2].x().size() );
CHECK( 3 == copy.f()[2].y().size() );
CHECK( 2 == copy.f()[3].x().size() );
CHECK( 2 == copy.f()[3].y().size() );
CHECK_THAT( -1. , WithinRel( copy.f()[0].x()[0] ) );
CHECK_THAT( 1. , WithinRel( copy.f()[0].x()[1] ) );
CHECK_THAT( 0.5 , WithinRel( copy.f()[0].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( copy.f()[0].y()[1] ) );
CHECK_THAT( -1. , WithinRel( copy.f()[1].x()[0] ) );
CHECK_THAT( 0. , WithinRel( copy.f()[1].x()[1] ) );
CHECK_THAT( 1. , WithinRel( copy.f()[1].x()[2] ) );
CHECK_THAT( 0.49, WithinRel( copy.f()[1].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( copy.f()[1].y()[1] ) );
CHECK_THAT( 0.51, WithinRel( copy.f()[1].y()[2] ) );
CHECK_THAT( -1. , WithinRel( copy.f()[2].x()[0] ) );
CHECK_THAT( 0. , WithinRel( copy.f()[2].x()[1] ) );
CHECK_THAT( 1. , WithinRel( copy.f()[2].x()[2] ) );
CHECK_THAT( 0.4 , WithinRel( copy.f()[2].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( copy.f()[2].y()[1] ) );
CHECK_THAT( 0.6 , WithinRel( copy.f()[2].y()[2] ) );
CHECK_THAT( -1. , WithinRel( copy.f()[3].x()[0] ) );
CHECK_THAT( 1. , WithinRel( copy.f()[3].x()[1] ) );
CHECK_THAT( 0.1 , WithinRel( copy.f()[3].y()[0] ) );
CHECK_THAT( 0.9 , WithinRel( copy.f()[3].y()[1] ) );
CHECK( 3 == copy.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == copy.interpolants()[0] );

Table2D move( x, f );
move = std::move( copy );

CHECK( 4 == move.numberPoints() );
CHECK( 1 == move.numberRegions() );
CHECK( 4 == move.x().size() );
CHECK( 4 == move.f().size() );
CHECK( 1 == move.boundaries().size() );
CHECK( 1 == move.interpolants().size() );
CHECK_THAT( 1., WithinRel( move.x()[0] ) );
CHECK_THAT( 2., WithinRel( move.x()[1] ) );
CHECK_THAT( 3., WithinRel( move.x()[2] ) );
CHECK_THAT( 4., WithinRel( move.x()[3] ) );
CHECK( 2 == move.f()[0].x().size() );
CHECK( 2 == move.f()[0].y().size() );
CHECK( 3 == move.f()[1].x().size() );
CHECK( 3 == move.f()[1].y().size() );
CHECK( 3 == move.f()[2].x().size() );
CHECK( 3 == move.f()[2].y().size() );
CHECK( 2 == move.f()[3].x().size() );
CHECK( 2 == move.f()[3].y().size() );
CHECK_THAT( -1. , WithinRel( move.f()[0].x()[0] ) );
CHECK_THAT( 1. , WithinRel( move.f()[0].x()[1] ) );
CHECK_THAT( 0.5 , WithinRel( move.f()[0].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( move.f()[0].y()[1] ) );
CHECK_THAT( -1. , WithinRel( move.f()[1].x()[0] ) );
CHECK_THAT( 0. , WithinRel( move.f()[1].x()[1] ) );
CHECK_THAT( 1. , WithinRel( move.f()[1].x()[2] ) );
CHECK_THAT( 0.49, WithinRel( move.f()[1].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( move.f()[1].y()[1] ) );
CHECK_THAT( 0.51, WithinRel( move.f()[1].y()[2] ) );
CHECK_THAT( -1. , WithinRel( move.f()[2].x()[0] ) );
CHECK_THAT( 0. , WithinRel( move.f()[2].x()[1] ) );
CHECK_THAT( 1. , WithinRel( move.f()[2].x()[2] ) );
CHECK_THAT( 0.4 , WithinRel( move.f()[2].y()[0] ) );
CHECK_THAT( 0.5 , WithinRel( move.f()[2].y()[1] ) );
CHECK_THAT( 0.6 , WithinRel( move.f()[2].y()[2] ) );
CHECK_THAT( -1. , WithinRel( move.f()[3].x()[0] ) );
CHECK_THAT( 1. , WithinRel( move.f()[3].x()[1] ) );
CHECK_THAT( 0.1 , WithinRel( move.f()[3].y()[0] ) );
CHECK_THAT( 0.9 , WithinRel( move.f()[3].y()[1] ) );
CHECK( 3 == move.boundaries()[0] );
CHECK( InterpolationType::LinearLinear == move.interpolants()[0] );
} // THEN

THEN( "an InterpolationTableFunction can be evaluated" ) {

// values of x in the x grid
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/IntervalDomain/src/ctor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
*/
IntervalDomain() = default;

IntervalDomain( const IntervalDomain& ) = default;
IntervalDomain( IntervalDomain&& ) = default;

IntervalDomain& operator=( const IntervalDomain& ) = default;
IntervalDomain& operator=( IntervalDomain&& ) = default;

/**
* @brief Constructor
*
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/LinearLinearTable/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
LinearLinearTable( const LinearLinearTable& ) = default;
LinearLinearTable( LinearLinearTable&& ) = default;

LinearLinearTable& operator=( const LinearLinearTable& ) = default;
LinearLinearTable& operator=( LinearLinearTable&& ) = default;

/**
* @brief Constructor
*
Expand Down
6 changes: 6 additions & 0 deletions src/scion/math/LinearLinearTableFunction/src/ctor.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
LinearLinearTableFunction( const LinearLinearTableFunction& ) = default;
LinearLinearTableFunction( LinearLinearTableFunction&& ) = default;

LinearLinearTableFunction& operator=( const LinearLinearTableFunction& ) = default;
LinearLinearTableFunction& operator=( LinearLinearTableFunction&& ) = default;

/**
* @brief Constructor
*
Expand Down
Loading

0 comments on commit ecad714

Please sign in to comment.