|
6 | 6 | from kwave.data import Vector |
7 | 7 | from kwave.kgrid import kWaveGrid |
8 | 8 |
|
9 | | -from kwave.utils.kwave_array import Element, kWaveArray |
| 9 | +from kwave.utils.kwave_array import kWaveArray |
10 | 10 | from tests.matlab_test_data_collectors.python_testers.utils.check_equality import check_kwave_array_equality |
11 | 11 | from tests.matlab_test_data_collectors.python_testers.utils.record_reader import TestRecordReader |
12 | 12 |
|
13 | 13 |
|
14 | | -def test_element_is_approximately_equal(): |
15 | | - base_element = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1]) |
16 | | - |
17 | | - # Test cases |
18 | | - assert base_element.is_close(Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1])) |
19 | | - assert base_element.is_close(Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1.000001])) |
20 | | - assert not base_element.is_close(Element(group_id=1, type="rect", dim=2, active=True, measure=2, position=[1, 1, 1])) |
21 | | - assert not base_element.is_close(Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[2, 2, 2])) |
22 | | - assert not base_element.is_close(Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, float('nan')])) |
23 | | - assert not base_element.is_close(Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, float('inf')])) |
24 | | - assert not base_element.is_close(Element(group_id=0, type="annular", dim=2, active=True, measure=1, position=[1, 1, 1])) |
25 | | - |
26 | | -def test_element_is_approximately_equal_nan(): |
27 | | - nan_element = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, float('nan')]) |
28 | | - assert nan_element.is_close(nan_element, equal_nan=True) |
29 | | - assert not nan_element.is_close(nan_element, equal_nan=False) |
30 | | - |
31 | | -def test_element_is_approximately_equal_boundary(): |
32 | | - base_element = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1]) |
33 | | - boundary_element = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1 + 1.1e-5]) |
34 | | - assert not base_element.is_close(boundary_element) |
35 | | - assert base_element.is_close(boundary_element, rtol=1.2e-5) |
36 | | - |
37 | | -def test_element_is_approximately_equal_consistency(): |
38 | | - base_element = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1]) |
39 | | - other_element = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1.000001]) |
40 | | - assert base_element.is_close(other_element) == np.allclose(base_element.position, other_element.position) |
41 | | - assert base_element.is_close(other_element) == base_element.is_close(other_element, rtol=1e-05, atol=1e-08, equal_nan=False) |
42 | | - |
43 | | -def test_element_is_approximately_equal_type_error(): |
44 | | - element = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1]) |
45 | | - |
46 | | - with pytest.raises(TypeError, match=r"not an element with <class 'str'> is not of type Element"): |
47 | | - element.is_close("not an element") |
48 | | - |
49 | | -def test_element_equality(): |
50 | | - element1 = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1]) |
51 | | - element2 = Element(group_id=0, type="rect", dim=2, active=True, measure=1, position=[1, 1, 1.000001]) |
52 | | - element3 = Element(group_id=1, type="rect", dim=2, active=True, measure=2, position=[1, 1, 1]) |
53 | | - |
54 | | - assert element1 == element1 |
55 | | - assert element1 != element2 |
56 | | - assert element1.is_approximately_equal(element2) |
57 | | - assert element1 != element3 |
58 | | - assert not element1.is_approximately_equal(element3) |
59 | | - assert element1 != element4 |
60 | | - assert not element1.is_approximately_equal(element4) |
61 | | - with pytest.raises(TypeError): |
62 | | - element1 != element5 |
63 | | - with pytest.raises(TypeError): |
64 | | - element1.is_approximately_equal(element5) |
65 | | - |
66 | | - |
67 | 14 | def test_kwave_array(): |
68 | 15 | test_record_path = os.path.join(Path(__file__).parent, "collectedValues/kWaveArray.mat") |
69 | 16 | reader = TestRecordReader(test_record_path) |
|
0 commit comments