diff --git a/CHANGELOG.md b/CHANGELOG.md index fe7da12..c7b567f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,9 @@ # Changelog of galpynostatic -## Unreleased +## v0.3.2 (2024-01-30) - `base` and `utils` modules are now tested directly. -- Better docs of `datasets` submodule and the three functions replaced in only one. +- Better docs of `datasets` submodule and the three functions replaced in only one. For each assert now there is a test. ## v0.3.1 (2024-01-29) diff --git a/pyproject.toml b/pyproject.toml index 80eb00f..41024a9 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -15,7 +15,7 @@ build-backend = "setuptools.build_meta" [project] name = "galpynostatic" -version = "0.3.1" +version = "0.3.2" authors = [{name = "Francisco Fernandez", email = "ffernandev@gmail.com"}] readme = "README.md" license = {file = "LICENSE"} diff --git a/tests/test_datasets.py b/tests/test_datasets.py index e60e64f..2c65cf5 100644 --- a/tests/test_datasets.py +++ b/tests/test_datasets.py @@ -25,64 +25,258 @@ # ============================================================================= -def test_load_planar(): - """Test the planar dataset.""" - pla = galpynostatic.datasets.load_dataset(geometry="planar") +# ============================================================================= +# planar geometry +# ============================================================================= + + +def test_planar_dataset_type(): + """Test the type of the planar dataset.""" + assert isinstance( + galpynostatic.datasets.load_dataset(geometry="planar"), pd.DataFrame + ) + + +def test_planar_dataset_logell_min(): + """Test minimum value of 'logell' in the planar dataset.""" + assert galpynostatic.datasets.load_dataset(geometry="planar").l.min() == -4 + + +def test_planar_dataset_logell_max(): + """Test maximum value of 'logell' in the planar dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="planar").l.max(), 1.75, 6 + ) + + +def test_planar_dataset_logell_mean(): + """Test mean value of 'logell' in the planar dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="planar").l.mean(), + -1.125, + 6, + ) + + +def test_planar_dataset_logxi_min(): + """Test minimum value of 'logxi' in the planar dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="planar").xi.min(), + -3.2, + 6, + ) + + +def test_planar_dataset_logxi_max(): + """Test maximum value of 'logxi' in the planar dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="planar").xi.max(), 2, 6 + ) + + +def test_planar_dataset_logxi_mean(): + """Test mean value of 'logxi' in the planar dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="planar").xi.mean(), + -0.6, + 6, + ) + + +def test_planar_dataset_xmax_min(): + """Test minimum value of 'xmax' in the planar dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="planar").xmax.min(), + 0.0, + 6, + ) + + +def test_planar_dataset_xmax_max(): + """Test maximum value of 'xmax' in the planar dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="planar").xmax.max(), + 0.997055, + 6, + ) + + +def test_planar_dataset_xmax_mean(): + """Test mean value of 'xmax' in the planar dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="planar").xmax.mean(), + 0.515846, + 6, + ) + + +# ============================================================================= +# cylindrical geometry +# ============================================================================= + + +def test_cylindrical_dataset_type(): + """Test the type of the cylindrical dataset.""" + assert isinstance( + galpynostatic.datasets.load_dataset(geometry="cylindrical"), + pd.DataFrame, + ) + + +def test_cylindrical_dataset_logell_min(): + """Test minimum value of 'logell' in the cylindrical dataset.""" + assert ( + galpynostatic.datasets.load_dataset(geometry="cylindrical").l.min() + == -4 + ) + + +def test_cylindrical_dataset_logell_max(): + """Test maximum value of 'logell' in the cylindrical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="cylindrical").l.max(), + 1.75, + 6, + ) + + +def test_cylindrical_dataset_logell_mean(): + """Test mean value of 'logell' in the cylindrical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="cylindrical").l.mean(), + -1.125, + 6, + ) + + +def test_cylindrical_dataset_logxi_min(): + """Test minimum value of 'logxi' in the cylindrical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="cylindrical").xi.min(), + -3.4, + 6, + ) + + +def test_cylindrical_dataset_logxi_max(): + """Test maximum value of 'logxi' in the cylindrical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="cylindrical").xi.max(), + 2, + 6, + ) + + +def test_cylindrical_dataset_logxi_mean(): + """Test mean value of 'logxi' in the cylindrical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="cylindrical").xi.mean(), + -0.7, + 6, + ) + + +def test_cylindrical_dataset_xmax_min(): + """Test minimum value of 'xmax' in the cylindrical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="cylindrical").xmax.min(), + 0.0, + 6, + ) + + +def test_cylindrical_dataset_xmax_max(): + """Test maximum value of 'xmax' in the cylindrical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset(geometry="cylindrical").xmax.max(), + 0.997055, + 6, + ) + + +def test_cylindrical_dataset_xmax_mean(): + """Test mean value of 'xmax' in the cylindrical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset( + geometry="cylindrical" + ).xmax.mean(), + 0.516647, + 6, + ) + + +# ============================================================================= +# spherical geometry +# ============================================================================= + + +def test_spherical_dataset_type(): + """Test the type of the spherical dataset.""" + assert isinstance(galpynostatic.datasets.load_dataset(), pd.DataFrame) + + +def test_spherical_dataset_logell_min(): + """Test minimum value of 'logell' in the spherical dataset.""" + assert galpynostatic.datasets.load_dataset().l.min() == -4 - assert isinstance(pla, pd.DataFrame) - assert pla.l.min() == -4 - np.testing.assert_almost_equal(pla.l.max(), 1.75, 6) - np.testing.assert_almost_equal(pla.l.mean(), -1.125, 6) +def test_spherical_dataset_logell_max(): + """Test maximum value of 'logell' in the spherical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset().l.max(), 1.75, 6 + ) - np.testing.assert_almost_equal(pla.xi.min(), -3.2, 6) - np.testing.assert_almost_equal(pla.xi.max(), 2, 6) - np.testing.assert_almost_equal(pla.xi.mean(), -0.6, 6) - np.testing.assert_almost_equal(pla.xmax.min(), 0.0, 6) - np.testing.assert_almost_equal(pla.xmax.max(), 0.997055, 6) - np.testing.assert_almost_equal(pla.xmax.mean(), 0.515846, 6) +def test_spherical_dataset_logell_mean(): + """Test mean value of 'logell' in the spherical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset().l.mean(), -1.125, 6 + ) -def test_load_cylindrical(): - """Test the cylindrical dataset.""" - cyl = galpynostatic.datasets.load_dataset(geometry="cylindrical") +def test_spherical_dataset_logxi_min(): + """Test minimum value of 'logxi' in the spherical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset().xi.min(), -3.5, 6 + ) - assert isinstance(cyl, pd.DataFrame) - assert cyl.l.min() == -4 - np.testing.assert_almost_equal(cyl.l.max(), 1.75, 6) - np.testing.assert_almost_equal(cyl.l.mean(), -1.125, 6) +def test_spherical_dataset_logxi_max(): + """Test maximum value of 'logxi' in the spherical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset().xi.max(), 2, 6 + ) - np.testing.assert_almost_equal(cyl.xi.min(), -3.4, 6) - np.testing.assert_almost_equal(cyl.xi.max(), 2, 6) - np.testing.assert_almost_equal(cyl.xi.mean(), -0.7, 6) - np.testing.assert_almost_equal(cyl.xmax.min(), 0.0, 6) - np.testing.assert_almost_equal(cyl.xmax.max(), 0.997055, 6) - np.testing.assert_almost_equal(cyl.xmax.mean(), 0.516647, 6) +def test_spherical_dataset_logxi_mean(): + """Test mean value of 'logxi' in the spherical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset().xi.mean(), -0.75, 6 + ) -def test_load_spherical(): - """Test the spherical dataset.""" - sph = galpynostatic.datasets.load_dataset() +def test_spherical_dataset_xmax_min(): + """Test minimum value of 'xmax' in the spherical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset().xmax.min(), 0.0, 6 + ) - assert isinstance(sph, pd.DataFrame) - assert sph.l.min() == -4 - np.testing.assert_almost_equal(sph.l.max(), 1.75, 6) - np.testing.assert_almost_equal(sph.l.mean(), -1.125, 6) +def test_spherical_dataset_xmax_max(): + """Test maximum value of 'xmax' in the spherical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset().xmax.max(), 0.99706, 6 + ) - np.testing.assert_almost_equal(sph.xi.min(), -3.5, 6) - np.testing.assert_almost_equal(sph.xi.max(), 2, 6) - np.testing.assert_almost_equal(sph.xi.mean(), -0.75, 6) - np.testing.assert_almost_equal(sph.xmax.min(), 0.0, 6) - np.testing.assert_almost_equal(sph.xmax.max(), 0.99706, 6) - np.testing.assert_almost_equal(sph.xmax.mean(), 0.518575, 6) +def test_spherical_dataset_xmax_mean(): + """Test mean value of 'xmax' in the spherical dataset.""" + np.testing.assert_almost_equal( + galpynostatic.datasets.load_dataset().xmax.mean(), 0.518575, 6 + ) -def test_raise(): +def test_value_error(): """Test the raise of the ValueError.""" with pytest.raises(ValueError): galpynostatic.datasets.load_dataset(geometry="plane")