diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 0684d6a..e94a92f 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -27,6 +27,10 @@ jobs: env: NUMBA_DISABLE_COVERAGE: "1" run: | - coverage run -m pytest -v -s - + coverage run -m pytest -v -s + - name: Upload coverage to Coveralls + if: matrix.os == 'ubuntu-latest' && matrix.python-version == '3.12' + run: coveralls --service=github + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} \ No newline at end of file diff --git a/README.md b/README.md index 170b2aa..35fb860 100644 --- a/README.md +++ b/README.md @@ -4,7 +4,7 @@ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/ObservationalExpansions/flex/blob/main/LICENSE) - +[![Coverage Status](https://coveralls.io/repos/github/ObservationalExpansions/flex/badge.svg?branch=main)](https://coveralls.io/github/ObservationalExpansions/flex?branch=main) ## Installation diff --git a/tests/test_flex.py b/tests/test_flex.py index 4c9ee9d..7c59807 100644 --- a/tests/test_flex.py +++ b/tests/test_flex.py @@ -46,9 +46,32 @@ def test_flex_initialization(): with pytest.raises(ValueError): flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity[:-1]) + # Test nonsense inputs + with pytest.raises(ValueError): + flex.FLEX(rscl, mmax, nmax, True, phi, mass, velocity) + with pytest.raises(ValueError): + flex.FLEX(rscl, mmax, nmax, R, True, mass, velocity) + with pytest.raises(ValueError): + flex.FLEX(rscl, mmax, nmax, R, phi, mass='nonsense') + with pytest.raises(ValueError): + flex.FLEX(rscl, mmax, nmax, R, phi, velocity='nonsense') + def test_flex_version(): assert isinstance(flex.__version__, str) +def test_flex_scalars(): + # Create a FLEX instance + rscl = 1.0 + mmax = 2 + nmax = 10 + R = np.linspace(0.1, 5.0, 100) + phi = np.linspace(0, 2*np.pi, 100) + mass = 1.0 + velocity = 1.0 + + F = flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity) + + def test_flex_total_power(): # Create a FLEX instance rscl = 1.0 @@ -59,7 +82,15 @@ def test_flex_total_power(): mass = np.random.uniform(0, 1, 100) velocity = np.random.uniform(0, 100, 100) - F = flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity) + # test the slower, careful, newaxis version + F = flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity, newaxis=True) + + # test the faster vectorised version + G = flex.FLEX(rscl, mmax, nmax, R, phi, mass, velocity) + + # check that both methods give the same coefficients + np.testing.assert_allclose(F.coscoefs, G.coscoefs) + np.testing.assert_allclose(F.sincoefs, G.sincoefs) # Compute total power in each harmonic totalm = np.linalg.norm(np.sqrt(F.coscoefs**2 + F.sincoefs**2), axis=1) @@ -68,4 +99,21 @@ def test_flex_total_power(): assert totalm.shape[0] == mmax + 1 # Check that totalm values are non-negative - assert np.all(totalm >= 0) \ No newline at end of file + assert np.all(totalm >= 0) + + +def test_flex_total_normalisation(): + # Create a FLEX instance + rscl = 1.0 + mmax = 0 + nmax = 1 + R = np.linspace(0.1, 5.0, 100) + phi = np.linspace(0, 2*np.pi, 100) + mass = np.ones(100) + + F = flex.FLEX(rscl, mmax, nmax, R, phi, mass) + + F.laguerre_reconstruction(R, phi) + + # check the values for the norm + #print(F.reconstruction)