Skip to content

Commit

Permalink
add test and coverage reports (#1)
Browse files Browse the repository at this point in the history
Run unit tests via GitHub actions and report coverage to Codecov.
  • Loading branch information
ntessore authored Nov 25, 2023
1 parent 9580440 commit ce2ea05
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 0 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Test
on:
push:
branches:
- main
pull_request:
branches:
- main
jobs:
tests:
name: Tests
runs-on: ubuntu-latest
strategy:
matrix:
python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"]
fail-fast: false
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: ${{ matrix.python-version }}
- run: pip install ".[test]"
- run: pytest --pyargs angst
- run: pytest --import-mode prepend --doctest-modules src/
coverage:
name: Coverage
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v4
with:
python-version: "3.12"
- run: pip install ".[test]" pytest-cov
- run: pytest --cov=angst --cov-report=xml
- uses: codecov/codecov-action@v3
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# **Angst** — Angular statistics

[![codecov](https://codecov.io/gh/ntessore/angst/graph/badge.svg?token=MPIHKHSRT4)](https://codecov.io/gh/ntessore/angst)

**Angst** is a _work-in-progress_ Python package for statistics on the sphere.

## Installation
Expand Down
2 changes: 2 additions & 0 deletions src/angst/_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
"""

from __future__ import annotations

__all__ = [
"inv_triangle_number",
]
Expand Down
46 changes: 46 additions & 0 deletions src/angst/test/test_points.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,3 +67,49 @@ def test_displace_abs(rng):
cos_a = np.cos(th) * np.cos(th_) + np.cos(delt) * np.sin(th) * np.sin(th_)

npt.assert_allclose(cos_a, np.cos(abs_alpha))


def test_displacement(rng):
from textwrap import dedent
import angst

# unit changes for displacements
deg5 = np.radians(5.0)
north = np.exp(1j * 0.0)
east = np.exp(1j * (np.pi / 2))
south = np.exp(1j * np.pi)
west = np.exp(1j * (3 * np.pi / 2))

# test data: coordinates and expected displacement
data = [
# equator
(0.0, 0.0, 0.0, 5.0, deg5 * north),
(0.0, 0.0, -5.0, 0.0, deg5 * east),
(0.0, 0.0, 0.0, -5.0, deg5 * south),
(0.0, 0.0, 5.0, 0.0, deg5 * west),
# pole
(0.0, 90.0, 180.0, 85.0, deg5 * north),
(0.0, 90.0, -90.0, 85.0, deg5 * east),
(0.0, 90.0, 0.0, 85.0, deg5 * south),
(0.0, 90.0, 90.0, 85.0, deg5 * west),
]

# test each displacement individually
for from_lon, from_lat, to_lon, to_lat, alpha in data:
alpha_ = angst.displacement(from_lon, from_lat, to_lon, to_lat)
assert np.allclose(alpha_, alpha), dedent(
f"""
displacement from ({from_lon}, {from_lat}) to ({to_lon}, {to_lat})
distance: expected {np.abs(alpha)}, got {np.abs(alpha_)}
direction: expected {np.angle(alpha)}, got {np.angle(alpha_)}
"""
)

# test on an array
alpha = angst.displacement(
rng.uniform(-180.0, 180.0, size=(20, 1)),
rng.uniform(-90.0, 90.0, size=(20, 1)),
rng.uniform(-180.0, 180.0, size=5),
rng.uniform(-90.0, 90.0, size=5),
)
assert alpha.shape == (20, 5)

0 comments on commit ce2ea05

Please sign in to comment.