Skip to content

Commit

Permalink
test negative cases in TestElement.test_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
janosh committed May 3, 2024
1 parent fc66bdf commit c06a24c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pymatgen/core/periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,8 +740,8 @@ def is_actinoid(self) -> bool:

@property
def is_radioactive(self) -> bool:
"""True if element is a radioactive element."""
return self.Z in (43, 61) or self.Z > 83
"""True if element is radioactive."""
return self.Z in (43, 61) or self.Z >= 84

@property
def is_quadrupolar(self) -> bool:
Expand Down
43 changes: 23 additions & 20 deletions tests/core/test_periodic_table.py
Original file line number Diff line number Diff line change
Expand Up @@ -227,22 +227,25 @@ def test_ground_state_term_symbol(self):
assert Element(key).ground_state_term_symbol == val

def test_attributes(self):
is_true = {
("Xe", "Kr"): "is_noble_gas",
("Fe", "Ni"): "is_transition_metal",
("Li", "Cs"): "is_alkali",
("Ca", "Mg"): "is_alkaline",
("F", "Br", "I"): "is_halogen",
("La",): "is_lanthanoid",
("U", "Pu"): "is_actinoid",
("Si", "Ge"): "is_metalloid",
("O", "Te"): "is_chalcogen",
("Tc", "Po"): "is_radioactive",
bool_attrs = {
("Xe", "Kr"): ("is_noble_gas", True),
("H", "Cl"): ("is_noble_gas", False),
("Fe", "Ni"): ("is_transition_metal", True),
("Li", "Cs"): ("is_alkali", True),
("Ca", "Mg"): ("is_alkaline", True),
("F", "Br", "I"): ("is_halogen", True),
("La", "Ce", "Lu"): ("is_lanthanoid", True),
("U", "Pu"): ("is_actinoid", True),
("Si", "Ge"): ("is_metalloid", True),
("O", "Te"): ("is_chalcogen", True),
("N", "Sb", "Ta"): ("is_chalcogen", False),
("Tc", "Po"): ("is_radioactive", True),
("H", "Li", "Bi"): ("is_radioactive", False),
}

for key, val in is_true.items():
for sym in key:
assert getattr(Element(sym), val), f"{sym=} is false"
for elements, (attr, expected) in bool_attrs.items():
for elem in elements:
assert getattr(Element(elem), attr) is expected, f"{elem=} {attr=}, {expected=}"

keys = (
"atomic_mass",
Expand Down Expand Up @@ -289,15 +292,15 @@ def test_attributes(self):
# Test all elements up to Uranium
for idx in range(1, 104):
el = Element.from_Z(idx)
for key in keys:
key_str = key.capitalize().replace("_", " ")
for elements in keys:
key_str = elements.capitalize().replace("_", " ")
if key_str in el.data and (not str(el.data[key_str]).startswith("no data")):
assert getattr(el, key) is not None
elif key == "long_name":
assert getattr(el, elements) is not None
elif elements == "long_name":
assert el.long_name == el.data["Name"]
elif key == "iupac_ordering":
elif elements == "iupac_ordering":
assert "IUPAC ordering" in el.data
assert getattr(el, key) is not None
assert getattr(el, elements) is not None

if len(el.oxidation_states) > 0:
assert max(el.oxidation_states) == el.max_oxidation_state
Expand Down

0 comments on commit c06a24c

Please sign in to comment.