Skip to content

Commit

Permalink
Tested materials and nuclei.
Browse files Browse the repository at this point in the history
  • Loading branch information
MicahGale committed Nov 28, 2024
1 parent 83a96fe commit e641fd3
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 32 deletions.
56 changes: 25 additions & 31 deletions tests/test_material.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,12 @@ def test_mat_get_nuclide_library(
if lib is None:
big_mat_lib.link_to_problem(prob_default)
assert big_mat_lib.get_nuclide_library(nuclide, lib_type) == lib
# test iter, items defaults
for iter_key, (item_key, item_val) in zip(
big_mat_lib.default_libraries, big_mat_lib.default_libraries.items()
):
assert iter_key == item_key
assert big_mat_lib.default_libraries[iter_key] == item_val

def test_mat_get_nuclide_library_bad(_, big_mat_lib):
with pytest.raises(TypeError):
Expand Down Expand Up @@ -363,37 +369,25 @@ def test_mat_comp_init_warn(_):
with pytest.raises(DeprecationWarning):
MaterialComponent(Nuclide("1001.80c"), 0.1)

def test_material_update_format(_):
# TODO update this
pass
"""
in_str = "M20 1001.80c 0.5 8016.80c 0.5"
input_card = Input([in_str], BlockType.DATA)
material = Material(input_card)
assert material.format_for_mcnp_input((6, 2, 0)) == [in_str]
material.number = 5
print(material.format_for_mcnp_input((6, 2, 0)))
assert "8016" in material.format_for_mcnp_input((6, 2, 0))[0]
# addition
isotope = Nuclide("2004.80c", suppress_warning=True)
with pytest.deprecated_call():
material.material_components[isotope] = MaterialComponent(isotope, 0.1, True)
print(material.format_for_mcnp_input((6, 2, 0)))
assert "2004" in material.format_for_mcnp_input((6, 2, 0))[0]
# update
isotope = list(material.material_components.keys())[-1]
print(material.material_components.keys())
material.material_components[isotope].fraction = 0.7
print(material.format_for_mcnp_input((6, 2, 0)))
assert "0.7" in material.format_for_mcnp_input((6, 2, 0))[0]
material.material_components[isotope] = MaterialComponent(isotope, 0.6, True)
print(material.format_for_mcnp_input((6, 2, 0)))
assert "0.6" in material.format_for_mcnp_input((6, 2, 0))[0]
# delete
del material.material_components[isotope]
print(material.format_for_mcnp_input((6, 2, 0)))
assert "8016" in material.format_for_mcnp_input((6, 2, 0))[0]
"""
def test_mat_eq(_, big_material):
new_mat = big_material.clone()
new_mat.number = big_material.number
assert new_mat == big_material
assert new_mat != 5
new_mat.values[-1] += 1.5
assert new_mat != big_material
new_mat.nuclides[-1].library = "09c"
assert new_mat != big_material
del new_mat[0]
assert new_mat != big_material
new_mat.number = 23
assert new_mat != big_material

def test_mat_long_str(_, big_material):
for i in range(23, 30):
big_material.add_nuclide(Nuclide(element=Element(i)), 0.123)
str(big_material)
repr(big_material)

@pytest.mark.parametrize(
"line, mat_number, is_atom, fractions",
Expand Down
21 changes: 20 additions & 1 deletion tests/test_nuclide.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,10 +227,15 @@ def test_library_sorting(_):
lib = Library("00c")
with pytest.raises(TypeError):
lib < 5
libs = {Library(s) for s in ["00c", "70c", "70g", "50d", "80m", "24y", "90a"]}
libs = {Library(s) for s in ["00c", "70c", "70g", "80m", "24y", "90a"]}
libs.add("50d")
gold_order = ["90a", "00c", "70c", "50d", "70g", "80m", "24y"]
assert [str(lib) for lib in sorted(libs)] == gold_order, "Sorting failed."

def test_library_bool(_):
assert Library("80c")
assert not Library("")


# test element
class TestElement:
Expand Down Expand Up @@ -280,3 +285,17 @@ def test_get_by_name(_):
def test_particle_str(_):
part = montepy.Particle("N")
assert str(part) == "neutron"


class TestNucleus:

@given(Z=st.integers(1, 99), A=st.integers(0, 300), meta=st.integers(0, 4))
def test_nucleus_init(_, Z, A, meta):
nucleus = Nucleus(Element(Z), A, meta)
assert nucleus.Z == Z
assert nucleus.A == A
assert nucleus.meta_state == meta
nuclide = Nuclide(nucleus.ZAID)
assert nuclide.nucleus == nucleus
nucleus(Element(Z))
assert nucleus.Z == Z

0 comments on commit e641fd3

Please sign in to comment.