Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ddasilva committed Nov 23, 2024
1 parent 3c191e9 commit 14d371c
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
[run]
omit = test*

[report]
omit = test*
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ __pycache__
*.vtk
*.so
*.o
.coverage

# Documentation
docs/api/*
Expand Down
4 changes: 0 additions & 4 deletions rbinvariantslib/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,10 +448,6 @@ def get_tsyganenko(
key = f"W{i}"
if key not in params:
params[key] = 0.0

if "dst" in params:
params["SymH"] = params["dst"]
del params["dst"]

gp_date = int(time.strftime("%Y%m%d"))
gp_ut = int(time.strftime("%H")) + time.minute / 60
Expand Down
2 changes: 2 additions & 0 deletions rbinvariantslib/tests/test_invariants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,5 @@ def test_lfm():

expected = 6.627379641675664
assert abs(result.LStar - expected) / expected < .05


38 changes: 38 additions & 0 deletions rbinvariantslib/tests/test_models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
from rbinvariantslib import models
import testing_utils


def test_lfm_interpolate():
"""Test interpolating LFM"""
fname = testing_utils.get_lfm_file()
model = models.get_model(
"lfm_hdf4",
fname
)

B_got = model.interpolate((-5, 0, 0))
B_expected = (-5.510784852447146e-06,
-2.583930850175165e-06,
0.0025205996644217495)

assert len(B_got) == len(B_expected)
assert abs(B_got[0] - B_expected[0]) < 1e-5
assert abs(B_got[1] - B_expected[1]) < 1e-5
assert abs(B_got[2] - B_expected[2]) < 1e-3


def test_get_dipole_on_lfm_grid():
"""Tests calculating dipole on LFM grid and interpolating value"""
fname = testing_utils.get_lfm_file()
model = models.get_dipole_model_on_lfm_grid(fname)

B_got = model.interpolate((-5, 0, 0))
B_expected = (6.779802670800632e-13,
3.559951359809801e-21,
-0.0024758772204116035)

assert len(B_got) == len(B_expected)
assert abs(B_got[0] - B_expected[0]) < 1e-5
assert abs(B_got[1] - B_expected[1]) < 1e-5
assert abs(B_got[2] - B_expected[2]) < 1e-3

0 comments on commit 14d371c

Please sign in to comment.