From d58f741b648a244004b9b757de18ca632dcce683 Mon Sep 17 00:00:00 2001 From: Wim Haeck Date: Thu, 30 Nov 2023 09:57:56 -0700 Subject: [PATCH] Updating test --- .../Test_scion_math_InterpolationTable.py | 154 ++++++++++++++---- .../test/InterpolationTable.test.cpp | 127 +++++++++++++-- 2 files changed, 233 insertions(+), 48 deletions(-) diff --git a/python/test/math/Test_scion_math_InterpolationTable.py b/python/test/math/Test_scion_math_InterpolationTable.py index aaac85d..06748a5 100644 --- a/python/test/math/Test_scion_math_InterpolationTable.py +++ b/python/test/math/Test_scion_math_InterpolationTable.py @@ -94,7 +94,7 @@ def verify_chunk1( self, chunk ) : # verify arithmetic operators same = InterpolationTable( [ 1., 4. ], [ 0., 3. ] ) threshold = InterpolationTable( [ 2., 4. ], [ 0., 2. ] ) - nonzerothreshold = InterpolationTable( [ 2., 4. ], [ 1., 2. ] ) + nonzerothreshold = InterpolationTable( [ 2., 4. ], [ 1., 3. ] ) small = InterpolationTable( [ 1., 3. ], [ 0., 2. ] ) result = -chunk @@ -313,7 +313,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, result.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) - chunk += same; + chunk += same self.assertEqual( 4, chunk.number_points ) self.assertEqual( 1, chunk.number_regions ) self.assertEqual( 4, len( chunk.x ) ) @@ -331,7 +331,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, chunk.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[0] ) - chunk -= same; + chunk -= same self.assertEqual( 4, chunk.number_points ) self.assertEqual( 1, chunk.number_regions ) self.assertEqual( 4, len( chunk.x ) ) @@ -349,7 +349,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, chunk.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[0] ) - result = chunk + same; + result = chunk + same self.assertEqual( 4, result.number_points ) self.assertEqual( 1, result.number_regions ) self.assertEqual( 4, len( result.x ) ) @@ -367,7 +367,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, result.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) - result = chunk - same; + result = chunk - same self.assertEqual( 4, result.number_points ) self.assertEqual( 1, result.number_regions ) self.assertEqual( 4, len( result.x ) ) @@ -385,7 +385,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, result.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) - chunk += threshold; + chunk += threshold self.assertEqual( 4, chunk.number_points ) self.assertEqual( 1, chunk.number_regions ) self.assertEqual( 4, len( chunk.x ) ) @@ -403,7 +403,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, chunk.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[0] ) - chunk -= threshold; + chunk -= threshold self.assertEqual( 4, chunk.number_points ) self.assertEqual( 1, chunk.number_regions ) self.assertEqual( 4, len( chunk.x ) ) @@ -421,7 +421,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, chunk.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[0] ) - result = chunk + threshold; + result = chunk + threshold self.assertEqual( 4, result.number_points ) self.assertEqual( 1, result.number_regions ) self.assertEqual( 4, len( result.x ) ) @@ -439,7 +439,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, result.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) - result = chunk - threshold; + result = chunk - threshold self.assertEqual( 4, result.number_points ) self.assertEqual( 1, result.number_regions ) self.assertEqual( 4, len( result.x ) ) @@ -457,8 +457,52 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 3, result.boundaries[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) + result = chunk + nonzerothreshold + self.assertEqual( 5, result.number_points ) + self.assertEqual( 2, result.number_regions ) + self.assertEqual( 5, len( result.x ) ) + self.assertEqual( 5, len( result.y ) ) + self.assertEqual( 2, len( result.boundaries ) ) + self.assertEqual( 2, len( result.interpolants ) ) + self.assertAlmostEqual( 1. , result.x[0] ) + self.assertAlmostEqual( 2. , result.x[1] ) + self.assertAlmostEqual( 2. , result.x[2] ) + self.assertAlmostEqual( 3. , result.x[3] ) + self.assertAlmostEqual( 4. , result.x[4] ) + self.assertAlmostEqual( 4.0, result.y[0] ) + self.assertAlmostEqual( 3.0, result.y[1] ) + self.assertAlmostEqual( 4.0, result.y[2] ) + self.assertAlmostEqual( 4.0, result.y[3] ) + self.assertAlmostEqual( 4.0, result.y[4] ) + self.assertEqual( 1, result.boundaries[0] ) + self.assertEqual( 4, result.boundaries[1] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) + + result = chunk - nonzerothreshold + self.assertEqual( 5, result.number_points ) + self.assertEqual( 2, result.number_regions ) + self.assertEqual( 5, len( result.x ) ) + self.assertEqual( 5, len( result.y ) ) + self.assertEqual( 2, len( result.boundaries ) ) + self.assertEqual( 2, len( result.interpolants ) ) + self.assertAlmostEqual( 1. , result.x[0] ) + self.assertAlmostEqual( 2. , result.x[1] ) + self.assertAlmostEqual( 2. , result.x[2] ) + self.assertAlmostEqual( 3. , result.x[3] ) + self.assertAlmostEqual( 4. , result.x[4] ) + self.assertAlmostEqual( 4., result.y[0] ) + self.assertAlmostEqual( 3., result.y[1] ) + self.assertAlmostEqual( 2., result.y[2] ) + self.assertAlmostEqual( 0., result.y[3] ) + self.assertAlmostEqual( -2., result.y[4] ) + self.assertEqual( 1, result.boundaries[0] ) + self.assertEqual( 4, result.boundaries[1] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) + # this will add a second point at the lower end point - result = chunk + small; + result = chunk + small self.assertEqual( 5, result.number_points ) self.assertEqual( 2, result.number_regions ) self.assertEqual( 5, len( result.x ) ) @@ -480,7 +524,7 @@ def verify_chunk1( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) # this will add a second point at the lower end point - result = chunk - small; + result = chunk - small self.assertEqual( 5, result.number_points ) self.assertEqual( 2, result.number_regions ) self.assertEqual( 5, len( result.x ) ) @@ -501,12 +545,6 @@ def verify_chunk1( self, chunk ) : self.assertEqual( 4, result.boundaries[1] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) - # the threshold table starts with a non-zero value - with self.assertRaises( Exception ) : chunk += nonzerothreshold - with self.assertRaises( Exception ) : chunk -= nonzerothreshold - with self.assertRaises( Exception ) : result = chunk + nonzerothreshold - with self.assertRaises( Exception ) : result = chunk - nonzerothreshold - def verify_chunk2( self, chunk ) : # verify content @@ -592,7 +630,7 @@ def verify_chunk2( self, chunk ) : # verify arithmetic operators same = InterpolationTable( [ 1., 4. ], [ 0., 3. ] ) threshold = InterpolationTable( [ 2., 4. ], [ 0., 2. ] ) - nonzerothreshold = InterpolationTable( [ 2., 4. ], [ 1., 2. ] ) + nonzerothreshold = InterpolationTable( [ 3., 4. ], [ 1., 2. ] ) small = InterpolationTable( [ 1., 3. ], [ 0., 2. ] ) result = -chunk @@ -835,7 +873,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) - chunk += same; + chunk += same self.assertEqual( 5, len( chunk.x ) ) self.assertEqual( 5, len( chunk.y ) ) self.assertEqual( 2, len( chunk.boundaries ) ) @@ -855,7 +893,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[1] ) - chunk -= same; + chunk -= same self.assertEqual( 5, len( chunk.x ) ) self.assertEqual( 5, len( chunk.y ) ) self.assertEqual( 2, len( chunk.boundaries ) ) @@ -875,7 +913,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[1] ) - result = chunk + same; + result = chunk + same self.assertEqual( 5, len( result.x ) ) self.assertEqual( 5, len( result.y ) ) self.assertEqual( 2, len( result.boundaries ) ) @@ -895,7 +933,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) - result = chunk - same; + result = chunk - same self.assertEqual( 5, len( result.x ) ) self.assertEqual( 5, len( result.y ) ) self.assertEqual( 2, len( result.boundaries ) ) @@ -915,7 +953,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) - chunk += threshold; + chunk += threshold self.assertEqual( 5, len( chunk.x ) ) self.assertEqual( 5, len( chunk.y ) ) self.assertEqual( 2, len( chunk.boundaries ) ) @@ -935,7 +973,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[1] ) - chunk -= threshold; + chunk -= threshold self.assertEqual( 5, len( chunk.x ) ) self.assertEqual( 5, len( chunk.y ) ) self.assertEqual( 2, len( chunk.boundaries ) ) @@ -955,7 +993,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, chunk.interpolants[1] ) - result = chunk + threshold; + result = chunk + threshold self.assertEqual( 5, len( result.x ) ) self.assertEqual( 5, len( result.y ) ) self.assertEqual( 2, len( result.boundaries ) ) @@ -975,7 +1013,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) - result = chunk - threshold; + result = chunk - threshold self.assertEqual( 5, len( result.x ) ) self.assertEqual( 5, len( result.y ) ) self.assertEqual( 2, len( result.boundaries ) ) @@ -995,8 +1033,56 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) + result = chunk + nonzerothreshold + self.assertEqual( 6, len( result.x ) ) + self.assertEqual( 6, len( result.y ) ) + self.assertEqual( 3, len( result.boundaries ) ) + self.assertEqual( 3, len( result.interpolants ) ) + self.assertAlmostEqual( 1., result.x[0] ) + self.assertAlmostEqual( 2., result.x[1] ) + self.assertAlmostEqual( 2., result.x[2] ) + self.assertAlmostEqual( 3., result.x[3] ) + self.assertAlmostEqual( 3., result.x[4] ) + self.assertAlmostEqual( 4., result.x[5] ) + self.assertAlmostEqual( 4., result.y[0] ) + self.assertAlmostEqual( 3., result.y[1] ) + self.assertAlmostEqual( 4., result.y[2] ) + self.assertAlmostEqual( 3., result.y[3] ) + self.assertAlmostEqual( 4., result.y[4] ) + self.assertAlmostEqual( 4., result.y[5] ) + self.assertEqual( 1, result.boundaries[0] ) + self.assertEqual( 3, result.boundaries[1] ) + self.assertEqual( 5, result.boundaries[2] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[2] ) + + result = chunk - nonzerothreshold + self.assertEqual( 6, len( result.x ) ) + self.assertEqual( 6, len( result.y ) ) + self.assertEqual( 3, len( result.boundaries ) ) + self.assertEqual( 3, len( result.interpolants ) ) + self.assertAlmostEqual( 1., result.x[0] ) + self.assertAlmostEqual( 2., result.x[1] ) + self.assertAlmostEqual( 2., result.x[2] ) + self.assertAlmostEqual( 3., result.x[3] ) + self.assertAlmostEqual( 3., result.x[4] ) + self.assertAlmostEqual( 4., result.x[5] ) + self.assertAlmostEqual( 4., result.y[0] ) + self.assertAlmostEqual( 3., result.y[1] ) + self.assertAlmostEqual( 4., result.y[2] ) + self.assertAlmostEqual( 3., result.y[3] ) + self.assertAlmostEqual( 2., result.y[4] ) + self.assertAlmostEqual( 0., result.y[5] ) + self.assertEqual( 1, result.boundaries[0] ) + self.assertEqual( 3, result.boundaries[1] ) + self.assertEqual( 5, result.boundaries[2] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[0] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) + self.assertEqual( InterpolationType.LinearLinear, result.interpolants[2] ) + # this will add a second point at the lower end point - result = chunk + small; + result = chunk + small self.assertEqual( 6, len( result.x ) ) self.assertEqual( 6, len( result.y ) ) self.assertEqual( 3, len( result.boundaries ) ) @@ -1021,7 +1107,7 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, result.interpolants[2] ) # this will add a second point at the lower end point - result = chunk - small; + result = chunk - small self.assertEqual( 6, len( result.x ) ) self.assertEqual( 6, len( result.y ) ) self.assertEqual( 3, len( result.boundaries ) ) @@ -1045,12 +1131,6 @@ def verify_chunk2( self, chunk ) : self.assertEqual( InterpolationType.LinearLinear, result.interpolants[1] ) self.assertEqual( InterpolationType.LinearLinear, result.interpolants[2] ) - # the threshold table starts with a non-zero value - with self.assertRaises( Exception ) : chunk += nonzerothreshold - with self.assertRaises( Exception ) : chunk -= nonzerothreshold - with self.assertRaises( Exception ) : result = chunk + nonzerothreshold - with self.assertRaises( Exception ) : result = chunk - nonzerothreshold - def verify_chunk3( self, chunk ) : # verify content @@ -1366,6 +1446,12 @@ def test_failures( self ) : chunk = InterpolationTable( x = [ 1., 2., 2., 2., 3., 4. ], y = [ 4., 3., 3., 3., 2., 1. ] ) + # the x grid has a jump at the beginning + with self.assertRaises( Exception ) : + + chunk = InterpolationTable( x = [ 1., 1., 3., 4. ], + y = [ 4., 3., 1., 4. ] ) + # the x grid has a jump at the end with self.assertRaises( Exception ) : diff --git a/src/scion/math/InterpolationTable/test/InterpolationTable.test.cpp b/src/scion/math/InterpolationTable/test/InterpolationTable.test.cpp index 122aaf9..2d0cbb8 100644 --- a/src/scion/math/InterpolationTable/test/InterpolationTable.test.cpp +++ b/src/scion/math/InterpolationTable/test/InterpolationTable.test.cpp @@ -89,7 +89,7 @@ SCENARIO( "InterpolationTable" ) { InterpolationTable< double > result( { 1., 4. }, { 0., 0. } ); InterpolationTable< double > same( { 1., 4. }, { 0., 3. } ); InterpolationTable< double > threshold( { 2., 4. }, { 0., 2. } ); - InterpolationTable< double > nonzerothreshold( { 2., 4. }, { 1., 2. } ); + InterpolationTable< double > nonzerothreshold( { 2., 4. }, { 1., 3. } ); InterpolationTable< double > small( { 1., 3. }, { 0., 2. } ); chunk += 2.; @@ -492,6 +492,54 @@ SCENARIO( "InterpolationTable" ) { CHECK( InterpolationType::LinearLinear == result.interpolants()[0] ); CHECK( true == std::holds_alternative< IntervalDomain< double > >( result.domain() ) ); + result = chunk + nonzerothreshold; + + CHECK( 5 == result.numberPoints() ); + CHECK( 2 == result.numberRegions() ); + CHECK( 5 == result.x().size() ); + CHECK( 5 == result.y().size() ); + CHECK( 2 == result.boundaries().size() ); + CHECK( 2 == result.interpolants().size() ); + CHECK_THAT( 1., WithinRel( result.x()[0] ) ); + CHECK_THAT( 2., WithinRel( result.x()[1] ) ); + CHECK_THAT( 2., WithinRel( result.x()[2] ) ); + CHECK_THAT( 3., WithinRel( result.x()[3] ) ); + CHECK_THAT( 4., WithinRel( result.x()[4] ) ); + CHECK_THAT( 4., WithinRel( result.y()[0] ) ); + CHECK_THAT( 3., WithinRel( result.y()[1] ) ); + CHECK_THAT( 4., WithinRel( result.y()[2] ) ); + CHECK_THAT( 4., WithinRel( result.y()[3] ) ); + CHECK_THAT( 4., WithinRel( result.y()[4] ) ); + CHECK( 1 == result.boundaries()[0] ); + CHECK( 4 == result.boundaries()[1] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[0] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[1] ); + CHECK( true == std::holds_alternative< IntervalDomain< double > >( result.domain() ) ); + + result = chunk - nonzerothreshold; + + CHECK( 5 == result.numberPoints() ); + CHECK( 2 == result.numberRegions() ); + CHECK( 5 == result.x().size() ); + CHECK( 5 == result.y().size() ); + CHECK( 2 == result.boundaries().size() ); + CHECK( 2 == result.interpolants().size() ); + CHECK_THAT( 1., WithinRel( result.x()[0] ) ); + CHECK_THAT( 2., WithinRel( result.x()[1] ) ); + CHECK_THAT( 2., WithinRel( result.x()[2] ) ); + CHECK_THAT( 3., WithinRel( result.x()[3] ) ); + CHECK_THAT( 4., WithinRel( result.x()[4] ) ); + CHECK_THAT( 4., WithinRel( result.y()[0] ) ); + CHECK_THAT( 3., WithinRel( result.y()[1] ) ); + CHECK_THAT( 2., WithinRel( result.y()[2] ) ); + CHECK_THAT( 0., WithinRel( result.y()[3] ) ); + CHECK_THAT( -2., WithinRel( result.y()[4] ) ); + CHECK( 1 == result.boundaries()[0] ); + CHECK( 4 == result.boundaries()[1] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[0] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[1] ); + CHECK( true == std::holds_alternative< IntervalDomain< double > >( result.domain() ) ); + // this will add a second point at the lower end point result = chunk + small; @@ -539,12 +587,6 @@ SCENARIO( "InterpolationTable" ) { CHECK( 4 == result.boundaries()[1] ); CHECK( InterpolationType::LinearLinear == result.interpolants()[0] ); CHECK( true == std::holds_alternative< IntervalDomain< double > >( result.domain() ) ); - - // the threshold table starts with a non-zero value - CHECK_THROWS( chunk += nonzerothreshold ); - CHECK_THROWS( chunk -= nonzerothreshold ); - CHECK_THROWS( result = chunk + nonzerothreshold ); - CHECK_THROWS( result = chunk - nonzerothreshold ); } // THEN THEN( "an InterpolationTable can be linearised" ) { @@ -687,7 +729,7 @@ SCENARIO( "InterpolationTable" ) { InterpolationTable< double > result( { 1., 4. }, { 0., 0. } ); InterpolationTable< double > same( { 1., 4. }, { 0., 3. } ); InterpolationTable< double > threshold( { 2., 4. }, { 0., 2. } ); - InterpolationTable< double > nonzerothreshold( { 2., 4. }, { 1., 2. } ); + InterpolationTable< double > nonzerothreshold( { 3., 4. }, { 1., 2. } ); InterpolationTable< double > small( { 1., 3. }, { 0., 2. } ); chunk += 2.; @@ -1130,6 +1172,58 @@ SCENARIO( "InterpolationTable" ) { CHECK( InterpolationType::LinearLinear == result.interpolants()[1] ); CHECK( true == std::holds_alternative< IntervalDomain< double > >( result.domain() ) ); + result = chunk + nonzerothreshold; + + CHECK( 6 == result.x().size() ); + CHECK( 6 == result.y().size() ); + CHECK( 3 == result.boundaries().size() ); + CHECK( 3 == result.interpolants().size() ); + CHECK_THAT( 1., WithinRel( result.x()[0] ) ); + CHECK_THAT( 2., WithinRel( result.x()[1] ) ); + CHECK_THAT( 2., WithinRel( result.x()[2] ) ); + CHECK_THAT( 3., WithinRel( result.x()[3] ) ); + CHECK_THAT( 3., WithinRel( result.x()[4] ) ); + CHECK_THAT( 4., WithinRel( result.x()[5] ) ); + CHECK_THAT( 4., WithinRel( result.y()[0] ) ); + CHECK_THAT( 3., WithinRel( result.y()[1] ) ); + CHECK_THAT( 4., WithinRel( result.y()[2] ) ); + CHECK_THAT( 3., WithinRel( result.y()[3] ) ); + CHECK_THAT( 4., WithinRel( result.y()[4] ) ); + CHECK_THAT( 4., WithinRel( result.y()[5] ) ); + CHECK( 1 == result.boundaries()[0] ); + CHECK( 3 == result.boundaries()[1] ); + CHECK( 5 == result.boundaries()[2] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[0] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[1] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[2] ); + CHECK( true == std::holds_alternative< IntervalDomain< double > >( result.domain() ) ); + + result = chunk - nonzerothreshold; + + CHECK( 6 == result.x().size() ); + CHECK( 6 == result.y().size() ); + CHECK( 3 == result.boundaries().size() ); + CHECK( 3 == result.interpolants().size() ); + CHECK_THAT( 1., WithinRel( result.x()[0] ) ); + CHECK_THAT( 2., WithinRel( result.x()[1] ) ); + CHECK_THAT( 2., WithinRel( result.x()[2] ) ); + CHECK_THAT( 3., WithinRel( result.x()[3] ) ); + CHECK_THAT( 3., WithinRel( result.x()[4] ) ); + CHECK_THAT( 4., WithinRel( result.x()[5] ) ); + CHECK_THAT( 4., WithinRel( result.y()[0] ) ); + CHECK_THAT( 3., WithinRel( result.y()[1] ) ); + CHECK_THAT( 4., WithinRel( result.y()[2] ) ); + CHECK_THAT( 3., WithinRel( result.y()[3] ) ); + CHECK_THAT( 2., WithinRel( result.y()[4] ) ); + CHECK_THAT( 0., WithinRel( result.y()[5] ) ); + CHECK( 1 == result.boundaries()[0] ); + CHECK( 3 == result.boundaries()[1] ); + CHECK( 5 == result.boundaries()[2] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[0] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[1] ); + CHECK( InterpolationType::LinearLinear == result.interpolants()[2] ); + CHECK( true == std::holds_alternative< IntervalDomain< double > >( result.domain() ) ); + // this will add a second point at the lower end point result = chunk + small; @@ -1183,12 +1277,6 @@ SCENARIO( "InterpolationTable" ) { CHECK( InterpolationType::LinearLinear == result.interpolants()[1] ); CHECK( InterpolationType::LinearLinear == result.interpolants()[2] ); CHECK( true == std::holds_alternative< IntervalDomain< double > >( result.domain() ) ); - - // the threshold table starts with a non-zero value - CHECK_THROWS( chunk += nonzerothreshold ); - CHECK_THROWS( chunk -= nonzerothreshold ); - CHECK_THROWS( result = chunk + nonzerothreshold ); - CHECK_THROWS( result = chunk - nonzerothreshold ); } // THEN } // WHEN } // GIVEN @@ -1569,6 +1657,17 @@ SCENARIO( "InterpolationTable" ) { } // THEN } // WHEN + WHEN( "the x grid has a jump at the beginning" ) { + + std::vector< double > x = { 1., 1., 3., 4. }; + std::vector< double > y = { 4., 3., 1., 4. }; + + THEN( "an exception is thrown" ) { + + CHECK_THROWS( InterpolationTable< double >( std::move( x ), std::move( y ) ) ); + } // THEN + } // WHEN + WHEN( "the x grid has a jump at the end" ) { std::vector< double > x = { 1., 2., 4., 4. };