Skip to content

Commit

Permalink
Updating test
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed Nov 30, 2023
1 parent 7edf07e commit d58f741
Show file tree
Hide file tree
Showing 2 changed files with 233 additions and 48 deletions.
154 changes: 120 additions & 34 deletions python/test/math/Test_scion_math_InterpolationTable.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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 ) )
Expand All @@ -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
Expand Down Expand Up @@ -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 ) :

Expand Down
Loading

0 comments on commit d58f741

Please sign in to comment.