Skip to content

Commit

Permalink
test per assert
Browse files Browse the repository at this point in the history
  • Loading branch information
fernandezfran committed Jan 30, 2024
1 parent b2121e3 commit 4030ba3
Show file tree
Hide file tree
Showing 3 changed files with 237 additions and 43 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down
274 changes: 234 additions & 40 deletions tests/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")

0 comments on commit 4030ba3

Please sign in to comment.