From e7929de762919d0014a7d7098c7a27e4e29fd2a5 Mon Sep 17 00:00:00 2001 From: Tingzheng Hou <25351437+htz1992213@users.noreply.github.com> Date: Mon, 5 Feb 2024 12:10:06 +0800 Subject: [PATCH] change assertion format --- tests/test_volume.py | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/tests/test_volume.py b/tests/test_volume.py index 2f2efcba..f0018e9c 100644 --- a/tests/test_volume.py +++ b/tests/test_volume.py @@ -3,6 +3,7 @@ import os import unittest +from numpy.testing import assert_allclose from pymatgen.core import Molecule from mdgo.util.volume import molecular_volume @@ -27,23 +28,23 @@ def test_molecular_volume(self) -> None: lipf6_volume_3 = molecular_volume(self.lipf6, radii_type="Lange") lipf6_volume_4 = molecular_volume(self.lipf6, radii_type="pymatgen") lipf6_volume_5 = molecular_volume(self.lipf6, molar_volume=False) - assert lipf6_volume_1 == 47.62 - assert lipf6_volume_2 == 43.36 - assert lipf6_volume_3 == 41.49 - assert lipf6_volume_4 == 51.94 - assert lipf6_volume_5 == 79.08 + assert_allclose(lipf6_volume_1, 47.62) + assert_allclose(lipf6_volume_2, 43.36) + assert_allclose(lipf6_volume_3, 41.49) + assert_allclose(lipf6_volume_4, 51.94) + assert_allclose(lipf6_volume_5, 79.08) ec_volume_1 = molecular_volume(self.ec) ec_volume_2 = molecular_volume(self.ec, exclude_h=False) ec_volume_3 = molecular_volume(self.ec, res=1.0) ec_volume_4 = molecular_volume(self.ec, radii_type="Lange") ec_volume_5 = molecular_volume(self.ec, radii_type="pymatgen") ec_volume_6 = molecular_volume(self.ec, molar_volume=False) - assert ec_volume_1 == 38.44 - assert ec_volume_2 == 43.17 - assert ec_volume_3 == 40.95 - assert ec_volume_4 == 41.07 - assert ec_volume_5 == 38.44 - assert ec_volume_6 == 63.83 + assert_allclose(ec_volume_1, 38.44) + assert_allclose(ec_volume_2, 43.17) + assert_allclose(ec_volume_3, 40.95) + assert_allclose(ec_volume_4, 41.07) + assert_allclose(ec_volume_5, 38.44) + assert_allclose(ec_volume_6, 63.83) litfsi_volume_1 = molecular_volume(self.litfsi) litfsi_volume_2 = molecular_volume(self.litfsi, exclude_h=False) litfsi_volume_3 = molecular_volume(self.litfsi, res=1.0) @@ -51,13 +52,13 @@ def test_molecular_volume(self) -> None: litfsi_volume_5 = molecular_volume(self.litfsi, radii_type="pymatgen") litfsi_volume_6 = molecular_volume(self.litfsi, molar_volume=False) litfsi_volume_7 = molecular_volume(self.litfsi, mode="act", x_size=8, y_size=8, z_size=8) - assert litfsi_volume_1 == 100.16 - assert litfsi_volume_2 == 100.16 - assert litfsi_volume_3 == 99.37 - assert litfsi_volume_4 == 90.78 - assert litfsi_volume_5 == 105.31 - assert litfsi_volume_6 == 166.32 - assert litfsi_volume_7 == 124.66 + assert_allclose(litfsi_volume_1, 100.16) + assert_allclose(litfsi_volume_2, 100.16) + assert_allclose(litfsi_volume_3, 99.37) + assert_allclose(litfsi_volume_4, 90.78) + assert_allclose(litfsi_volume_5, 105.31) + assert_allclose(litfsi_volume_6, 166.32) + assert_allclose(litfsi_volume_7, 124.66) if __name__ == "__main__":