Skip to content

Commit

Permalink
waltsims#460: addressed PR comments wrt coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
precicely committed Sep 1, 2024
1 parent f217a0d commit 393fc68
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kwave/utils/kwave_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def is_close(self, other: "Element", rtol=1e-05, atol=1e-08, equal_nan=False):
for field in fields(self):
self_attr = getattr(self, field.name)
other_attr = getattr(other, field.name)
if isinstance(self_attr, (int, float, np.ndarray)):
if isinstance(self_attr, (float, np.ndarray)):
if not np.allclose(self_attr, other_attr, rtol=rtol, atol=atol, equal_nan=equal_nan):
return False
else:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@
from kwave.data import Vector
from kwave.kgrid import kWaveGrid

from kwave.utils.kwave_array import kWaveArray
from kwave.utils.kwave_array import Element, kWaveArray
from tests.matlab_test_data_collectors.python_testers.utils.check_equality import check_kwave_array_equality
from tests.matlab_test_data_collectors.python_testers.utils.record_reader import TestRecordReader


def test_element():
element1 = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1])
# element2 has a very similar position to element 1 but with a small numerical difference
element2 = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1.000001])
element3 = "not an element"
assert element1 != element2
assert element1.is_close(element2)
with pytest.raises(Exception):
element1 != element3
element1.is_close(element3)


def test_kwave_array():
test_record_path = os.path.join(Path(__file__).parent, "collectedValues/kWaveArray.mat")
reader = TestRecordReader(test_record_path)
Expand Down

0 comments on commit 393fc68

Please sign in to comment.