From 7e2ea28182ad7a940e55e7f9185d4088f1128304 Mon Sep 17 00:00:00 2001 From: BitterB0NG0 <93603537+BitterB0NG0@users.noreply.github.com> Date: Wed, 27 Nov 2024 00:54:16 -0700 Subject: [PATCH] tests/test_cell: added cell option tests --- scripts/_data.py | 62 +-- scripts/build_test_cell_options.py | 188 +++++++ src/pymcnp/files/inp/cell_option.py | 2 +- .../files/inp/subclasses_cell_options/cosy.py | 2 +- .../files/inp/subclasses_cell_options/fill.py | 22 +- .../files/inp/subclasses_cell_options/lat.py | 2 +- .../files/inp/subclasses_cell_options/nonu.py | 2 +- .../files/inp/subclasses_cell_options/unc.py | 2 +- tests/test_cell.py | 495 ++++++++++++++---- 9 files changed, 635 insertions(+), 142 deletions(-) create mode 100644 scripts/build_test_cell_options.py diff --git a/scripts/_data.py b/scripts/_data.py index 9c46592..472ccf3 100644 --- a/scripts/_data.py +++ b/scripts/_data.py @@ -212,7 +212,7 @@ def __init__(self, *, mnemonic: str = None, attributes: tuple[AttributeScheme] = name='setting', type='types.McnpInteger', description='Cell fission setting.', - restriction='setting in {0, 1, 2}', + restriction='setting.value in {0, 1, 2}', error='INVALID_CELL_OPTION_VALUE', ), ), @@ -286,7 +286,7 @@ def __init__(self, *, mnemonic: str = None, attributes: tuple[AttributeScheme] = name='shape', type='types.McnpInteger', description='Cell lattice shape.', - restriction='shape in {1, 2}', + restriction='shape.value in {1, 2}', error='INVALID_CELL_OPTION_VALUE', ), ), @@ -295,10 +295,10 @@ def __init__(self, *, mnemonic: str = None, attributes: tuple[AttributeScheme] = mnemonic='fill', attributes=( AttributeScheme( - name='numbers', - type='tuple[types.McnpInteger]', + name='number', + type='types.McnpInteger', description='Fill cell option value or value(s) tuple.', - restriction='0 <= entry <= 99_999_999', + restriction='0 <= number <= 99_999_999', error='INVALID_CELL_OPTION_VALUE', ), ), @@ -329,7 +329,7 @@ def __init__(self, *, mnemonic: str = None, attributes: tuple[AttributeScheme] = name='number', type='types.McnpInteger', description='Cell cosy map number.', - restriction='number in {1, 2, 3, 4, 5, 6}', + restriction='number.value in {1, 2, 3, 4, 5, 6}', error='INVALID_CELL_OPTION_VALUE', ), ), @@ -353,7 +353,7 @@ def __init__(self, *, mnemonic: str = None, attributes: tuple[AttributeScheme] = name='setting', type='types.McnpInteger', description='Cell uncollided secondaries setting.', - restriction='setting in {0, 1}', + restriction='setting.value in {0, 1}', error='INVALID_CELL_OPTION_VALUE', ), AttributeScheme( @@ -2532,7 +2532,7 @@ def __init__( name='form', type='str', description='Format specification of the embedded mesh input file', - restriction='form in {"lnk3dnt", "abaqu", "mcnpum"}', + restriction='form.value in {"lnk3dnt", "abaqu", "mcnpum"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -2572,7 +2572,7 @@ def __init__( name='setting', type='str', description='Yes/no calculate the inferred geometry cell information', - restriction='setting in {"yes", "no"}', + restriction='setting.value in {"yes", "no"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -2582,7 +2582,7 @@ def __init__( name='parameter', type='str', description='Debug parameter', - restriction='parameter in {"echomesh"}', + restriction='parameter.value in {"echomesh"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -2592,7 +2592,7 @@ def __init__( name='kind', type='str', description='File type for the elemental edit output file', - restriction='type in {"ascii", "binary"}', + restriction='type.value in {"ascii", "binary"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -2684,7 +2684,7 @@ def __init__( name='setting', type='str', description='Flag to multiply by atom density', - restriction='setting in {"yes", "no"}', + restriction='setting.value in {"yes", "no"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -2714,7 +2714,7 @@ def __init__( name='kind', type='str', description='Multiplier type', - restriction='type in {"flux", "isotropic", "population", "reaction", "source", "track"}', + restriction='type.value in {"flux", "isotropic", "population", "reaction", "source", "track"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -2899,7 +2899,7 @@ def __init__( name='setting', type='str', description='Flag for density-effect correction to electron stopping power', - restriction='setting in {"yes", "no"}', + restriction='setting.value in {"yes", "no"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3200,7 +3200,7 @@ def __init__( name='mcal', type='str', description='Problem type setting', - restriction='mcal in {"f", "a"}', + restriction='mcal.value in {"f", "a"}', error='INVALID_DATA_PARAMETER', ), AttributeScheme( @@ -3296,7 +3296,7 @@ def __init__( name='kind', type='str', description='Type of delayed particle(s) to be produced from residuals created by fission', - restriction='type in {"none", "n,p,e,f,a", "all"}', + restriction='type.value in {"none", "n,p,e,f,a", "all"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3306,7 +3306,7 @@ def __init__( name='kind', type='str', description='Type of delayed particle(s) to be produced by simple multi-particle reaction', - restriction='type in {"none", "n,p,e,f,a", "all"}', + restriction='type.value in {"none", "n,p,e,f,a", "all"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3316,7 +3316,7 @@ def __init__( name='source', type='str', description='Delayed neutron data source', - restriction='source in {"model", "library", "both", "prompt"}', + restriction='source.value in {"model", "library", "both", "prompt"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3326,7 +3326,7 @@ def __init__( name='source', type='str', description='Delayed gamma data source', - restriction='source in {"line", "mg", "none"}', + restriction='source.value in {"line", "mg", "none"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3386,7 +3386,7 @@ def __init__( name='setting', type='str', description='Flag for correlated or uncorrelated', - restriction='setting in {"correlate", "nonfiss_cor"}', + restriction='setting.value in {"correlate", "nonfiss_cor"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3861,7 +3861,7 @@ def __init__( name='setting', type='str', description='Multiple coulomb scattering setting', - restriction='setting in {"off", "fnal1", "gaussian", "fnal2"}', + restriction='setting.value in {"off", "fnal1", "gaussian", "fnal2"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3871,7 +3871,7 @@ def __init__( name='setting', type='str', description='Slowing down energy losses setting', - restriction='setting in {"off", "strag1", "csda"}', + restriction='setting.value in {"off", "strag1", "csda"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3881,7 +3881,7 @@ def __init__( name='setting', type='str', description='Nuclear reactions setting', - restriction='setting in {"off", "on", "atten", "remove"}', + restriction='setting.value in {"off", "on", "atten", "remove"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3891,7 +3891,7 @@ def __init__( name='setting', type='str', description='Nuclear elastic scattering setting', - restriction='setting in {"off", "on"}', + restriction='setting.value in {"off", "on"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -3967,7 +3967,7 @@ def __init__( name='kind', type='str', description='Magnetic field type', - restriction='type in {"const", "quad", "quadff"}', + restriction='type.value in {"const", "quad", "quadff"}', error='INVALID_DATA_PARAMETER', ), AttributeScheme( @@ -4537,7 +4537,7 @@ def __init__( name='setting', type='str', description='Yes/No calculate point-kinetics parameters', - restriction='setting in {"yes", "no"}', + restriction='setting.value in {"yes", "no"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -4547,7 +4547,7 @@ def __init__( name='setting', type='str', description='Yes/No detailed precursor information', - restriction='setting in {"yes", "no"}', + restriction='setting.value in {"yes", "no"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -4557,7 +4557,7 @@ def __init__( name='fileopt', type='str', description='Format of sensity profiles output file', - restriction='fileopt in {",mctal"}', + restriction='fileopt.value in {",mctal"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -4567,7 +4567,7 @@ def __init__( name='setting', type='str', description='Yes/No FMAT', - restriction='setting in {"yes", "no"}', + restriction='setting.value in {"yes", "no"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -4607,7 +4607,7 @@ def __init__( name='setting', type='str', description='fmataccel', - restriction='setting in {"yes", "no"}', + restriction='setting.value in {"yes", "no"}', error='INVALID_DATA_OPTION_VALUE', ), ), @@ -4617,7 +4617,7 @@ def __init__( name='setting', type='str', description='fmatreduce', - restriction='setting in {"yes", "no"}', + restriction='setting.value in {"yes", "no"}', error='INVALID_DATA_OPTION_VALUE', ), ), diff --git a/scripts/build_test_cell_options.py b/scripts/build_test_cell_options.py new file mode 100644 index 0000000..74c1159 --- /dev/null +++ b/scripts/build_test_cell_options.py @@ -0,0 +1,188 @@ +""" +Contains script for building ``TestCellOption`` subclasses. +""" + +from typing import Final + +import _data + + +class CellOptionTestScheme: + """ + Stores attribute metadata for metaprogramming. + + Attributes: + name: Cell option name for ``CellOption``. + valid: List of valid test parameters. + invalid: List of invalid test parameters. + """ + + def __init__(self, name: str, valid: tuple[any], invalid: tuple[any]): + """ + Initializies ``CellOptionTestScheme``. + + Attributes: + name: Cell option name for ``CellOption``. + valid: List of valid ``CellOption`` test parameters. + invalid: List of invalid ``CellOption`` test parameters. + """ + + self.valid: Final[tuple[any]] = valid + self.invalid: Final[tuple[any]] = invalid + + +CELL_OPTION_TESTS: Final[tuple[CellOptionTestScheme]] = ( + CellOptionTestScheme( + name='Imp', + valid=[(0.5, ('n', 'p')), (1.5, ('n')), (-0.5, ('n', '#'))], + invalid=[], + ), + CellOptionTestScheme( + name='Vol', + valid=[0.5, 1.5, 0.0], + invalid=[-1.5, -2.5, -0.1], + ), + CellOptionTestScheme( + name='Pwt', + valid=[0.5, 1.5, -0.5], + invalid=[], + ), + CellOptionTestScheme( + name='Ext', + valid=[('0.5', ('n', 'p')), ('0.9', ('n')), ('-0.5', ('n', '#'))], + invalid=[], + ), + CellOptionTestScheme( + name='Fcl', + valid=[(0.5, ('n', 'p')), (0.9, ('n')), (-0.5, ('n', '#'))], + invalid=[(2.51, ('n', 'p')), (3.94, ('n')), (-1.3, ('n', '#'))], + ), + CellOptionTestScheme( + name='Wwn', + valid=[(0.5, 3, ('n', 'p')), (0.9, 8, ('n')), (-1.0, 2, ('n', '#'))], + invalid=[], + ), + CellOptionTestScheme( + name='Dxc', + valid=[(0.5, 3, ('n', 'p')), (0.9, 8, ('n')), (0.0, 2, ('n', '#'))], + invalid=[(-1.0, 2, ('n'))], + ), + CellOptionTestScheme( + name='Nonu', + valid=[0, 1, 2], + invalid=[-1, 3, 100], + ), + CellOptionTestScheme( + name='Pd', + valid=[(0, 5), (0.5, 7), (1, 3)], + invalid=[(-1, 1), (3, 2), (100, 5)], + ), + CellOptionTestScheme( + name='Tmp', + valid=[(4.26, 1), (3.14, 5), (0.24, 7), (9.43, 3)], + invalid=[(-0.53, 1), (00.00, 2), (-1.43, 5)], + ), + CellOptionTestScheme( + name='U', + valid=[-99_999_999, 99_999_999, 0, 1, -1], + invalid=[-100_000_000, 100_000_000, 100_000_432], + ), + CellOptionTestScheme( + name='Trcl', + valid=[1, 67, 999], + invalid=[-1000, 1000, 2343], + ), + CellOptionTestScheme( + name='Lat', + valid=[1, 2], + invalid=[0, -1, 100], + ), + CellOptionTestScheme( + name='Fill', + valid=[0, 234, 99_999_999], + invalid=[-100, 100_000_000, -1], + ), + CellOptionTestScheme( + name='Elpt', + valid=[(-234.05434, ('n', 'p')), (345034950, ('n')), (34534.3453, ('n', '#'))], + invalid=[], + ), + CellOptionTestScheme( + name='Cosy', + valid=[1, 2, 3, 4, 5, 6], + invalid=[0, 100_000_000, -1], + ), + CellOptionTestScheme( + name='Bflcl', + valid=[0, 4, 10], + invalid=[-1, -345, -1000], + ), + CellOptionTestScheme( + name='Unc', + valid=[(0, ('#')), (1, ('e'))], + invalid=[(-1, ('n', '#')), (345, ('@', '#')), (-1000, ('e')), (2, ('p', '_'))], + ), +) + + +def build_TestCellOption(cell_option: _data.CellOptionScheme, test: CellOptionTestScheme): + o = '' + + # TEST_VALID + + o += f'class Test_Cell{cell_option.name}:\n' + o += ' """\n' + o += f' Tests ``Cell{cell_option.name}``.\n' + o += ' """\n' + o += '\n' + o += f' VALID_EXAMPLES = {str(test.valid)}\n' + o += '\n' + o += f' INVALID_EXAMPLES = {str(test.invalid)}\n' + o += '\n' + o += ' def test_valid(self):\n' + o += f' for {", ".join(attribute.name for attribute in cell_option.attributes)} in self.VALID_EXAMPLES:\n' + + for attribute in cell_option.attributes: + if attribute.type.startswith('types'): + o += ( + f' _{attribute.name} = pymcnp.utils.{attribute.type}({attribute.name})\n' + ) + elif attribute.type == 'str': + o += f' _{attribute.name} = {attribute.name}\n' + else: + o += f' _{attribute.name} = {attribute.type}({attribute.name})\n' + + o += '\n' + o += f' obj = pymcnp.inp.Cell{cell_option.name}(_{", _".join(attribute.name for attribute in cell_option.attributes)})\n' + o += '\n' + o += f' assert obj.keyword == pymcnp.inp.CellKeyword.{cell_option.enum}\n' + + for attribute in cell_option.attributes: + if attribute.type.startswith('types'): + o += f' assert obj.{attribute.name} == pymcnp.utils.{attribute.type}({attribute.name})\n' + elif attribute.type == 'str': + o += f' assert obj.{attribute.name} == {attribute.name}\n' + else: + o += f' assert obj.{attribute.name} == {attribute.type}({attribute.name})\n' + + o += '\n' + o += ' def test_invalid(self):\n' + o += f' for {", ".join(attribute.name for attribute in cell_option.attributes)} in self.INVALID_EXAMPLES:\n' + o += ' with pytest.raises(pymcnp.utils.errors.McnpError):\n' + + for attribute in cell_option.attributes: + if attribute.type.startswith('types'): + o += f' {attribute.name} = pymcnp.utils.{attribute.type}({attribute.name})\n' + elif attribute.type == 'str': + o += f' {attribute.name} = {attribute.name}\n' + else: + o += f' {attribute.name} = {attribute.type}({attribute.name})\n' + + o += f' pymcnp.inp.Cell{cell_option.name}({", ".join(attribute.name for attribute in cell_option.attributes)})\n' + o += '\n' + + return o + + +for cell_option, test in zip(_data.CELL_OPTIONS, CELL_OPTION_TESTS): + print(build_TestCellOption(cell_option, test)) diff --git a/src/pymcnp/files/inp/cell_option.py b/src/pymcnp/files/inp/cell_option.py index c27c958..ea2ab0f 100644 --- a/src/pymcnp/files/inp/cell_option.py +++ b/src/pymcnp/files/inp/cell_option.py @@ -28,7 +28,7 @@ class CellKeyword(_card.CardKeyword): # FILL_ANGLE = '*fill' ELPT = 'elpt' COSY = 'cosy' - BFIELD = 'bflcl' + BFLCL = 'bflcl' UNC = 'unc' @staticmethod diff --git a/src/pymcnp/files/inp/subclasses_cell_options/cosy.py b/src/pymcnp/files/inp/subclasses_cell_options/cosy.py index e3662df..bd0fcae 100644 --- a/src/pymcnp/files/inp/subclasses_cell_options/cosy.py +++ b/src/pymcnp/files/inp/subclasses_cell_options/cosy.py @@ -30,7 +30,7 @@ def __init__(self, number: types.McnpInteger): McnpError: INVALID_CELL_OPTION_VALUE. """ - if number is None or number not in {1, 2, 3, 4, 5, 6}: + if number is None or number.value not in {1, 2, 3, 4, 5, 6}: raise errors.McnpError(errors.McnpCode.INVALID_CELL_OPTION_VALUE, str(number)) self.keyword: Final[CellKeyword] = CellKeyword.COSY diff --git a/src/pymcnp/files/inp/subclasses_cell_options/fill.py b/src/pymcnp/files/inp/subclasses_cell_options/fill.py index 3d21b8e..cd96f04 100644 --- a/src/pymcnp/files/inp/subclasses_cell_options/fill.py +++ b/src/pymcnp/files/inp/subclasses_cell_options/fill.py @@ -16,30 +16,26 @@ class Fill(CellOption): ``Fill`` implements ``_card.CardOption``. Attributes: - numbers: Fill cell option value or value(s) tuple. + number: Fill cell option value or value(s) tuple. """ - def __init__(self, numbers: tuple[types.McnpInteger]): + def __init__(self, number: types.McnpInteger): """ Initializes ``Fill``. Parameters: - numbers: Fill cell option value or value(s) tuple. + number: Fill cell option value or value(s) tuple. Raises: McnpError: INVALID_CELL_OPTION_VALUE. """ - if numbers is None: - raise errors.McnpError(errors.McnpCode.INVALID_CELL_OPTION_VALUE, str(numbers)) - - for entry in numbers: - if entry is None or not (0 <= entry <= 99_999_999): - raise errors.McnpError(errors.McnpCode.INVALID_CELL_OPTION_VALUE, str(numbers)) + if number is None or not (0 <= number <= 99_999_999): + raise errors.McnpError(errors.McnpCode.INVALID_CELL_OPTION_VALUE, str(number)) self.keyword: Final[CellKeyword] = CellKeyword.FILL - self.value: Final[tuple[types.McnpInteger]] = numbers - self.numbers: Final[tuple[types.McnpInteger]] = numbers + self.value: Final[types.McnpInteger] = number + self.number: Final[types.McnpInteger] = number @staticmethod def from_mcnp(source: str): @@ -70,6 +66,6 @@ def from_mcnp(source: str): raise errors.McnpError(errors.McnpCode.UNRECOGNIZED_KEYWORD, str(keyword)) tokens.popl() - numbers = tuple([types.McnpInteger.from_mcnp(tokens.popl()) for _ in range(0, len(tokens))]) + number = types.McnpInteger.from_mcnp(tokens.popl()) - return Fill(numbers) + return Fill(number) diff --git a/src/pymcnp/files/inp/subclasses_cell_options/lat.py b/src/pymcnp/files/inp/subclasses_cell_options/lat.py index 3e1e51a..70949ac 100644 --- a/src/pymcnp/files/inp/subclasses_cell_options/lat.py +++ b/src/pymcnp/files/inp/subclasses_cell_options/lat.py @@ -30,7 +30,7 @@ def __init__(self, shape: types.McnpInteger): McnpError: INVALID_CELL_OPTION_VALUE. """ - if shape is None or shape not in {1, 2}: + if shape is None or shape.value not in {1, 2}: raise errors.McnpError(errors.McnpCode.INVALID_CELL_OPTION_VALUE, str(shape)) self.keyword: Final[CellKeyword] = CellKeyword.LAT diff --git a/src/pymcnp/files/inp/subclasses_cell_options/nonu.py b/src/pymcnp/files/inp/subclasses_cell_options/nonu.py index f84ea3b..5f08d7a 100644 --- a/src/pymcnp/files/inp/subclasses_cell_options/nonu.py +++ b/src/pymcnp/files/inp/subclasses_cell_options/nonu.py @@ -30,7 +30,7 @@ def __init__(self, setting: types.McnpInteger): McnpError: INVALID_CELL_OPTION_VALUE. """ - if setting is None or setting not in {0, 1, 2}: + if setting is None or setting.value not in {0, 1, 2}: raise errors.McnpError(errors.McnpCode.INVALID_CELL_OPTION_VALUE, str(setting)) self.keyword: Final[CellKeyword] = CellKeyword.NONU diff --git a/src/pymcnp/files/inp/subclasses_cell_options/unc.py b/src/pymcnp/files/inp/subclasses_cell_options/unc.py index 8280692..9089e44 100644 --- a/src/pymcnp/files/inp/subclasses_cell_options/unc.py +++ b/src/pymcnp/files/inp/subclasses_cell_options/unc.py @@ -33,7 +33,7 @@ def __init__(self, setting: types.McnpInteger, designator: types.Designator): McnpError: INVALID_CELL_OPTION_DESIGNATOR. """ - if setting is None or setting not in {0, 1}: + if setting is None or setting.value not in {0, 1}: raise errors.McnpError(errors.McnpCode.INVALID_CELL_OPTION_VALUE, str(setting)) if designator is None: raise errors.McnpError(errors.McnpCode.INVALID_CELL_OPTION_DESIGNATOR, str(designator)) diff --git a/tests/test_cell.py b/tests/test_cell.py index 94f25e6..4d23204 100644 --- a/tests/test_cell.py +++ b/tests/test_cell.py @@ -92,7 +92,7 @@ def test_valid(self): assert pymcnp.inp.CellKeyword.from_mcnp('fill') == pymcnp.inp.CellKeyword.FILL assert pymcnp.inp.CellKeyword.from_mcnp('elpt') == pymcnp.inp.CellKeyword.ELPT assert pymcnp.inp.CellKeyword.from_mcnp('cosy') == pymcnp.inp.CellKeyword.COSY - assert pymcnp.inp.CellKeyword.from_mcnp('bflcl') == pymcnp.inp.CellKeyword.BFIELD + assert pymcnp.inp.CellKeyword.from_mcnp('bflcl') == pymcnp.inp.CellKeyword.BFLCL assert pymcnp.inp.CellKeyword.from_mcnp('unc') == pymcnp.inp.CellKeyword.UNC def test_invalid(self): @@ -108,31 +108,52 @@ class Test_CellImp: Tests ``CellImp``. """ - VALID_EXAMPLES = [ - (0.5, ('n', 'p')), - (1.5, ('n')), - (-0.5, ('n', '#')), - ] + VALID_EXAMPLES = [(0.5, ('n', 'p')), (1.5, 'n'), (-0.5, ('n', '#'))] INVALID_EXAMPLES = [] + def test_valid(self): + for importance, designator in self.VALID_EXAMPLES: + _importance = pymcnp.utils.types.McnpReal(importance) + _designator = pymcnp.utils.types.Designator(designator) + + obj = pymcnp.inp.CellImp(_importance, _designator) + + assert obj.keyword == pymcnp.inp.CellKeyword.IMP + assert obj.importance == pymcnp.utils.types.McnpReal(importance) + assert obj.designator == pymcnp.utils.types.Designator(designator) + + def test_invalid(self): + for importance, designator in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + importance = pymcnp.utils.types.McnpReal(importance) + designator = pymcnp.utils.types.Designator(designator) + pymcnp.inp.CellImp(importance, designator) + class Test_CellVol: """ Tests ``CellVol``. """ - VALID_EXAMPLES = [ - 0.5, - 1.5, - 0.0, - ] + VALID_EXAMPLES = [0.5, 1.5, 0.0] - INVALID_EXAMPLES = [ - -1.5, - -2.5, - -0.1, - ] + INVALID_EXAMPLES = [-1.5, -2.5, -0.1] + + def test_valid(self): + for volume in self.VALID_EXAMPLES: + _volume = pymcnp.utils.types.McnpReal(volume) + + obj = pymcnp.inp.CellVol(_volume) + + assert obj.keyword == pymcnp.inp.CellKeyword.VOL + assert obj.volume == pymcnp.utils.types.McnpReal(volume) + + def test_invalid(self): + for volume in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + volume = pymcnp.utils.types.McnpReal(volume) + pymcnp.inp.CellVol(volume) class Test_CellPwt: @@ -140,45 +161,80 @@ class Test_CellPwt: Tests ``CellPwt``. """ - VALID_EXAMPLES = [ - 0.5, - 1.5, - -0.5, - ] + VALID_EXAMPLES = [0.5, 1.5, -0.5] INVALID_EXAMPLES = [] + def test_valid(self): + for weight in self.VALID_EXAMPLES: + _weight = pymcnp.utils.types.McnpReal(weight) + + obj = pymcnp.inp.CellPwt(_weight) + + assert obj.keyword == pymcnp.inp.CellKeyword.PWT + assert obj.weight == pymcnp.utils.types.McnpReal(weight) + + def test_invalid(self): + for weight in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + weight = pymcnp.utils.types.McnpReal(weight) + pymcnp.inp.CellPwt(weight) + class Test_CellExt: """ Tests ``CellExt``. """ - VALID_EXAMPLES = [ - ('0.5', 'p'), - ('0.9', '#'), - ('-0.5', 'n'), - ] + VALID_EXAMPLES = [('0.5', ('n', 'p')), ('0.9', 'n'), ('-0.5', ('n', '#'))] INVALID_EXAMPLES = [] + def test_valid(self): + for stretch, designator in self.VALID_EXAMPLES: + _stretch = stretch + _designator = pymcnp.utils.types.Designator(designator) + + obj = pymcnp.inp.CellExt(_stretch, _designator) + + assert obj.keyword == pymcnp.inp.CellKeyword.EXT + assert obj.stretch == stretch + assert obj.designator == pymcnp.utils.types.Designator(designator) + + def test_invalid(self): + for stretch, designator in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + stretch = stretch + designator = pymcnp.utils.types.Designator(designator) + pymcnp.inp.CellExt(stretch, designator) + class Test_CellFcl: """ Tests ``CellFcl``. """ - VALID_EXAMPLES = [ - (0.5, 'p'), - (0.9, '#'), - (-0.5, 'n'), - ] + VALID_EXAMPLES = [(0.5, ('n', 'p')), (0.9, 'n'), (-0.5, ('n', '#'))] - INVALID_EXAMPLES = [ - (2.51, 'p'), - (3.94, '#'), - (-1.3, 'n'), - ] + INVALID_EXAMPLES = [(2.51, ('n', 'p')), (3.94, 'n'), (-1.3, ('n', '#'))] + + def test_valid(self): + for control, designator in self.VALID_EXAMPLES: + _control = pymcnp.utils.types.McnpReal(control) + _designator = pymcnp.utils.types.Designator(designator) + + obj = pymcnp.inp.CellFcl(_control, _designator) + + assert obj.keyword == pymcnp.inp.CellKeyword.FCL + assert obj.control == pymcnp.utils.types.McnpReal(control) + assert obj.designator == pymcnp.utils.types.Designator(designator) + + def test_invalid(self): + for control, designator in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + control = pymcnp.utils.types.McnpReal(control) + designator = pymcnp.utils.types.Designator(designator) + pymcnp.inp.CellFcl(control, designator) class Test_CellWwn: @@ -186,92 +242,345 @@ class Test_CellWwn: Tests ``CellWwn``. """ - VALID_EXAMPLES = [ - (0.5, 3, 'p'), - (0.9, 8, '#'), - (-1.0, 2, 'n'), - ] + VALID_EXAMPLES = [(0.5, 3, ('n', 'p')), (0.9, 8, 'n'), (-1.0, 2, ('n', '#'))] INVALID_EXAMPLES = [] + def test_valid(self): + for bound, suffix, designator in self.VALID_EXAMPLES: + _bound = pymcnp.utils.types.McnpReal(bound) + _suffix = pymcnp.utils.types.McnpInteger(suffix) + _designator = pymcnp.utils.types.Designator(designator) + + obj = pymcnp.inp.CellWwn(_bound, _suffix, _designator) + + assert obj.keyword == pymcnp.inp.CellKeyword.WWN + assert obj.bound == pymcnp.utils.types.McnpReal(bound) + assert obj.suffix == pymcnp.utils.types.McnpInteger(suffix) + assert obj.designator == pymcnp.utils.types.Designator(designator) + + def test_invalid(self): + for bound, suffix, designator in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + bound = pymcnp.utils.types.McnpReal(bound) + suffix = pymcnp.utils.types.McnpInteger(suffix) + designator = pymcnp.utils.types.Designator(designator) + pymcnp.inp.CellWwn(bound, suffix, designator) + class Test_CellDxc: """ Tests ``CellDxc``. """ - VALID_EXAMPLES = [ - (0.5, 3, 'p'), - (0.9, 8, '#'), - (0.0, 2, 'n'), - ] + VALID_EXAMPLES = [(0.5, 3, ('n', 'p')), (0.9, 8, 'n'), (0.0, 2, ('n', '#'))] - INVALID_EXAMPLES = [ - (-1.0, 2, '_'), - ] + INVALID_EXAMPLES = [(-1.0, 2, 'n')] + def test_valid(self): + for probability, suffix, designator in self.VALID_EXAMPLES: + _probability = pymcnp.utils.types.McnpReal(probability) + _suffix = pymcnp.utils.types.McnpInteger(suffix) + _designator = pymcnp.utils.types.Designator(designator) -# class Test_CellNonu: -# """ -# Tests ``CellNonu``. -# """ + obj = pymcnp.inp.CellDxc(_probability, _suffix, _designator) + assert obj.keyword == pymcnp.inp.CellKeyword.DXC + assert obj.probability == pymcnp.utils.types.McnpReal(probability) + assert obj.suffix == pymcnp.utils.types.McnpInteger(suffix) + assert obj.designator == pymcnp.utils.types.Designator(designator) -# class Test_CellPd: -# """ -# Tests ``CellPd``. -# """ + def test_invalid(self): + for probability, suffix, designator in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + probability = pymcnp.utils.types.McnpReal(probability) + suffix = pymcnp.utils.types.McnpInteger(suffix) + designator = pymcnp.utils.types.Designator(designator) + pymcnp.inp.CellDxc(probability, suffix, designator) -# class Test_CellTmp: -# """ -# Tests ``CellTmp``. -# """ +class Test_CellNonu: + """ + Tests ``CellNonu``. + """ + VALID_EXAMPLES = [0, 1, 2] -# class Test_CellU: -# """ -# Tests ``CellU``. -# """ + INVALID_EXAMPLES = [-1, 3, 100] + def test_valid(self): + for setting in self.VALID_EXAMPLES: + _setting = pymcnp.utils.types.McnpInteger(setting) -# class Test_CellTrcl: -# """ -# Tests ``CellTrcl``. -# """ + obj = pymcnp.inp.CellNonu(_setting) + assert obj.keyword == pymcnp.inp.CellKeyword.NONU + assert obj.setting == pymcnp.utils.types.McnpInteger(setting) -# class Test_CellLat: -# """ -# Tests ``CellLat``. -# """ + def test_invalid(self): + for setting in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + setting = pymcnp.utils.types.McnpInteger(setting) + pymcnp.inp.CellNonu(setting) -# class Test_CellFill: -# """ -# Tests ``CellFill``. -# """ +class Test_CellPd: + """ + Tests ``CellPd``. + """ + VALID_EXAMPLES = [(0, 5), (0.5, 7), (1, 3)] -# class Test_CellElpt: -# """ -# Tests ``CellElpt``. -# """ + INVALID_EXAMPLES = [(-1, 1), (3, 2), (100, 5)] + + def test_valid(self): + for probability, suffix in self.VALID_EXAMPLES: + _probability = pymcnp.utils.types.McnpReal(probability) + _suffix = pymcnp.utils.types.McnpInteger(suffix) + obj = pymcnp.inp.CellPd(_probability, _suffix) -# class Test_CellCosy: -# """ -# Tests ``CellCosy``. -# """ + assert obj.keyword == pymcnp.inp.CellKeyword.PD + assert obj.probability == pymcnp.utils.types.McnpReal(probability) + assert obj.suffix == pymcnp.utils.types.McnpInteger(suffix) + def test_invalid(self): + for probability, suffix in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + probability = pymcnp.utils.types.McnpReal(probability) + suffix = pymcnp.utils.types.McnpInteger(suffix) + pymcnp.inp.CellPd(probability, suffix) + + +class Test_CellTmp: + """ + Tests ``CellTmp``. + """ + + VALID_EXAMPLES = [(4.26, 1), (3.14, 5), (0.24, 7), (9.43, 3)] + + INVALID_EXAMPLES = [(-0.53, 1), (0.0, 2), (-1.43, 5)] + + def test_valid(self): + for temperature, suffix in self.VALID_EXAMPLES: + _temperature = pymcnp.utils.types.McnpReal(temperature) + _suffix = pymcnp.utils.types.McnpInteger(suffix) + + obj = pymcnp.inp.CellTmp(_temperature, _suffix) + + assert obj.keyword == pymcnp.inp.CellKeyword.TMP + assert obj.temperature == pymcnp.utils.types.McnpReal(temperature) + assert obj.suffix == pymcnp.utils.types.McnpInteger(suffix) + + def test_invalid(self): + for temperature, suffix in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + temperature = pymcnp.utils.types.McnpReal(temperature) + suffix = pymcnp.utils.types.McnpInteger(suffix) + pymcnp.inp.CellTmp(temperature, suffix) + + +class Test_CellU: + """ + Tests ``CellU``. + """ + + VALID_EXAMPLES = [-99999999, 99999999, 0, 1, -1] + + INVALID_EXAMPLES = [-100000000, 100000000, 100000432] + + def test_valid(self): + for number in self.VALID_EXAMPLES: + _number = pymcnp.utils.types.McnpInteger(number) -# class Test_CellBflcl: -# """ -# Tests ``CellBflcl``. -# """ + obj = pymcnp.inp.CellU(_number) + assert obj.keyword == pymcnp.inp.CellKeyword.U + assert obj.number == pymcnp.utils.types.McnpInteger(number) -# class Test_CellUnc: -# """ -# Tests ``CellUnc``. -# """ + def test_invalid(self): + for number in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + number = pymcnp.utils.types.McnpInteger(number) + pymcnp.inp.CellU(number) + + +class Test_CellTrcl: + """ + Tests ``CellTrcl``. + """ + + VALID_EXAMPLES = [1, 67, 999] + + INVALID_EXAMPLES = [-1000, 1000, 2343] + + def test_valid(self): + for value in self.VALID_EXAMPLES: + _value = int(value) + + obj = pymcnp.inp.CellTrcl(_value) + + assert obj.keyword == pymcnp.inp.CellKeyword.TRCL + assert obj.value == int(value) + + def test_invalid(self): + for value in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + value = int(value) + pymcnp.inp.CellTrcl(value) + + +class Test_CellLat: + """ + Tests ``CellLat``. + """ + + VALID_EXAMPLES = [1, 2] + + INVALID_EXAMPLES = [0, -1, 100] + + def test_valid(self): + for shape in self.VALID_EXAMPLES: + _shape = pymcnp.utils.types.McnpInteger(shape) + + obj = pymcnp.inp.CellLat(_shape) + + assert obj.keyword == pymcnp.inp.CellKeyword.LAT + assert obj.shape == pymcnp.utils.types.McnpInteger(shape) + + def test_invalid(self): + for shape in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + shape = pymcnp.utils.types.McnpInteger(shape) + pymcnp.inp.CellLat(shape) + + +class Test_CellFill: + """ + Tests ``CellFill``. + """ + + VALID_EXAMPLES = [0, 234, 99999999] + + INVALID_EXAMPLES = [-100, 100000000, -1] + + def test_valid(self): + for number in self.VALID_EXAMPLES: + _number = pymcnp.utils.types.McnpInteger(number) + + obj = pymcnp.inp.CellFill(_number) + + assert obj.keyword == pymcnp.inp.CellKeyword.FILL + assert obj.number == pymcnp.utils.types.McnpInteger(number) + + def test_invalid(self): + for number in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + number = pymcnp.utils.types.McnpInteger(number) + pymcnp.inp.CellFill(number) + + +class Test_CellElpt: + """ + Tests ``CellElpt``. + """ + + VALID_EXAMPLES = [(-234.05434, ('n', 'p')), (345034950, 'n'), (34534.3453, ('n', '#'))] + + INVALID_EXAMPLES = [] + + def test_valid(self): + for cutoff, designator in self.VALID_EXAMPLES: + _cutoff = pymcnp.utils.types.McnpReal(cutoff) + _designator = pymcnp.utils.types.Designator(designator) + + obj = pymcnp.inp.CellElpt(_cutoff, _designator) + + assert obj.keyword == pymcnp.inp.CellKeyword.ELPT + assert obj.cutoff == pymcnp.utils.types.McnpReal(cutoff) + assert obj.designator == pymcnp.utils.types.Designator(designator) + + def test_invalid(self): + for cutoff, designator in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + cutoff = pymcnp.utils.types.McnpReal(cutoff) + designator = pymcnp.utils.types.Designator(designator) + pymcnp.inp.CellElpt(cutoff, designator) + + +class Test_CellCosy: + """ + Tests ``CellCosy``. + """ + + VALID_EXAMPLES = [1, 2, 3, 4, 5, 6] + + INVALID_EXAMPLES = [0, 100000000, -1] + + def test_valid(self): + for number in self.VALID_EXAMPLES: + _number = pymcnp.utils.types.McnpInteger(number) + + obj = pymcnp.inp.CellCosy(_number) + + assert obj.keyword == pymcnp.inp.CellKeyword.COSY + assert obj.number == pymcnp.utils.types.McnpInteger(number) + + def test_invalid(self): + for number in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + number = pymcnp.utils.types.McnpInteger(number) + pymcnp.inp.CellCosy(number) + + +class Test_CellBflcl: + """ + Tests ``CellBflcl``. + """ + + VALID_EXAMPLES = [0, 4, 10] + + INVALID_EXAMPLES = [-1, -345, -1000] + + def test_valid(self): + for number in self.VALID_EXAMPLES: + _number = pymcnp.utils.types.McnpInteger(number) + + obj = pymcnp.inp.CellBflcl(_number) + + assert obj.keyword == pymcnp.inp.CellKeyword.BFLCL + assert obj.number == pymcnp.utils.types.McnpInteger(number) + + def test_invalid(self): + for number in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + number = pymcnp.utils.types.McnpInteger(number) + pymcnp.inp.CellBflcl(number) + + +class Test_CellUnc: + """ + Tests ``CellUnc``. + """ + + VALID_EXAMPLES = [(0, '#'), (1, 'e')] + + INVALID_EXAMPLES = [(-1, ('n', '#')), (345, ('@', '#')), (-1000, 'e'), (2, ('p', '_'))] + + def test_valid(self): + for setting, designator in self.VALID_EXAMPLES: + _setting = pymcnp.utils.types.McnpInteger(setting) + _designator = pymcnp.utils.types.Designator(designator) + + obj = pymcnp.inp.CellUnc(_setting, _designator) + + assert obj.keyword == pymcnp.inp.CellKeyword.UNC + assert obj.setting == pymcnp.utils.types.McnpInteger(setting) + assert obj.designator == pymcnp.utils.types.Designator(designator) + + def test_invalid(self): + for setting, designator in self.INVALID_EXAMPLES: + with pytest.raises(pymcnp.utils.errors.McnpError): + setting = pymcnp.utils.types.McnpInteger(setting) + designator = pymcnp.utils.types.Designator(designator) + pymcnp.inp.CellUnc(setting, designator)