From 7e895c5fd6d1ad452e95f986be84153b1b5a0ec6 Mon Sep 17 00:00:00 2001 From: "Haoyu (Daniel)" Date: Sat, 25 Jan 2025 18:03:19 +0100 Subject: [PATCH] add test for reduce formula --- tests/core/test_composition.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/core/test_composition.py b/tests/core/test_composition.py index 00366b253d4..ab8a7c8666f 100644 --- a/tests/core/test_composition.py +++ b/tests/core/test_composition.py @@ -12,7 +12,7 @@ from pytest import approx from pymatgen.core import Composition, DummySpecies, Element, Species -from pymatgen.core.composition import ChemicalPotential, CompositionError +from pymatgen.core.composition import ChemicalPotential, CompositionError, reduce_formula from pymatgen.util.testing import PymatgenTest @@ -860,6 +860,12 @@ def test_isotopes(self): assert "Deuterium" in [elem.long_name for elem in composition.elements] +def test_reduce_formula(): + assert reduce_formula({"Li": 2, "Mn": 4, "O": 8}) == ("LiMn2O4", 2) + assert reduce_formula({"Li": 4, "O": 4}) == ("LiO", 4) + assert reduce_formula({"Zn": 2, "O": 2, "H": 2}) == ("ZnHO", 2) + + def test_composition_error(): error = CompositionError("Composition error") assert isinstance(error, CompositionError)