Skip to content

Commit

Permalink
Adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
whaeck committed May 17, 2024
1 parent 9551662 commit 50a4d5e
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmake/unit_testing_python.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,6 @@ add_python_test( multigroup.Kerma multigroup/Test_NDItk_
add_python_test( multigroup.OutgoingParticleTypes multigroup/Test_NDItk_multigroup_OutgoingParticleTypes.py )
add_python_test( multigroup.OutgoingParticleTransportData multigroup/Test_NDItk_multigroup_OutgoingParticleTransportData.py )
add_python_test( multigroup.LegendreMoment multigroup/Test_NDItk_multigroup_LegendreMoment.py )
add_python_test( multigroup.ScatteringMatrix multigroup/Test_NDItk_multigroup_ScatteringMatrix.py )

add_python_test( MultigroupTable Test_NDItk_MultigroupTable.py )
2 changes: 2 additions & 0 deletions python/src/multigroup.python.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ namespace multigroup {
void wrapOutgoingParticleTypes( python::module&, python::module& );
void wrapOutgoingParticleTransportData( python::module&, python::module& );
void wrapLegendreMoment( python::module&, python::module& );
void wrapScatteringMatrix( python::module&, python::module& );
}

void wrapMultigroup( python::module& module, python::module& viewmodule ) {
Expand All @@ -47,4 +48,5 @@ void wrapMultigroup( python::module& module, python::module& viewmodule ) {
multigroup::wrapOutgoingParticleTypes( submodule, viewmodule );
multigroup::wrapOutgoingParticleTransportData( submodule, viewmodule );
multigroup::wrapLegendreMoment( submodule, viewmodule );
multigroup::wrapScatteringMatrix( submodule, viewmodule );
}
99 changes: 99 additions & 0 deletions python/test/multigroup/Test_NDItk_multigroup_ScatteringMatrix.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# standard imports
import unittest

# third party imports

# local imports
from NDItk.multigroup import ScatteringMatrix
from NDItk.multigroup import LegendreMoment

class Test_NDItk_multigroup_ScatteringMatrix( unittest.TestCase ) :
"""Unit test for the ScatteringMatrix class."""

chunk_values = [ 0,
1, 2, 3, 4, 5, 6,
1,
11, 12, 13, 14, 15, 16 ]
chunk_string = ( 'pn_full\n'
' 0\n'
' 1 2 3 4 5\n'
' 6\n'
' 1\n'
' 11 12 13 14 15\n'
' 16\n' )

def test_component( self ) :

def verify_chunk( self, chunk ) :

# verify content
self.assertEqual( 3, chunk.number_primary_groups )
self.assertEqual( 2, chunk.number_outgoing_groups )
self.assertEqual( 2, chunk.number_legendre_moments )

self.assertEqual( True, chunk.has_moment( 0 ) )
self.assertEqual( True, chunk.has_moment( 1 ) )
self.assertEqual( False, chunk.has_moment( 102 ) )

self.assertEqual( 0, chunk.moments[0].order )
self.assertAlmostEqual( 1, chunk.moments[0].matrix[0][0] )
self.assertAlmostEqual( 2, chunk.moments[0].matrix[0][1] )
self.assertAlmostEqual( 3, chunk.moments[0].matrix[1][0] )
self.assertAlmostEqual( 4, chunk.moments[0].matrix[1][1] )
self.assertAlmostEqual( 5, chunk.moments[0].matrix[2][0] )
self.assertAlmostEqual( 6, chunk.moments[0].matrix[2][1] )

self.assertEqual( 1, chunk.moments[1].order )
self.assertAlmostEqual( 11, chunk.moments[1].matrix[0][0] )
self.assertAlmostEqual( 12, chunk.moments[1].matrix[0][1] )
self.assertAlmostEqual( 13, chunk.moments[1].matrix[1][0] )
self.assertAlmostEqual( 14, chunk.moments[1].matrix[1][1] )
self.assertAlmostEqual( 15, chunk.moments[1].matrix[2][0] )
self.assertAlmostEqual( 16, chunk.moments[1].matrix[2][1] )

moment = chunk.moment( 0 )
self.assertEqual( 0, moment.order )
self.assertAlmostEqual( 1, moment.matrix[0][0] )
self.assertAlmostEqual( 2, moment.matrix[0][1] )
self.assertAlmostEqual( 3, moment.matrix[1][0] )
self.assertAlmostEqual( 4, moment.matrix[1][1] )
self.assertAlmostEqual( 5, moment.matrix[2][0] )
self.assertAlmostEqual( 6, moment.matrix[2][1] )

moment = chunk.moment( 1 )
self.assertEqual( 1, moment.order )
self.assertAlmostEqual( 11, moment.matrix[0][0] )
self.assertAlmostEqual( 12, moment.matrix[0][1] )
self.assertAlmostEqual( 13, moment.matrix[1][0] )
self.assertAlmostEqual( 14, moment.matrix[1][1] )
self.assertAlmostEqual( 15, moment.matrix[2][0] )
self.assertAlmostEqual( 16, moment.matrix[2][1] )

self.assertEqual( self.chunk_string, chunk.to_string() )

# verify the record
self.assertEqual( 'pn_full', chunk.keyword )
self.assertEqual( False, chunk.empty )
self.assertEqual( 14, chunk.size )

values = chunk.values
for index in range( chunk.size ) :

self.assertAlmostEqual( self.chunk_values[index], values[index] )

# the data is given explicitly
chunk = ScatteringMatrix(
moments = [ LegendreMoment( 0, [ 1, 2, 3, 4, 5, 6 ], 3, 2 ),
LegendreMoment( 1, [ 11, 12, 13, 14, 15, 16 ], 3, 2 ) ] )

verify_chunk( self, chunk )

# the data is read from a string
chunk = ScatteringMatrix.from_string( self.chunk_string, 3, 2, 2 )

verify_chunk( self, chunk )

if __name__ == '__main__' :

unittest.main()

0 comments on commit 50a4d5e

Please sign in to comment.