Skip to content

Commit

Permalink
Improve test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
iguinn committed Oct 14, 2024
1 parent a1cf2b2 commit 0a0bffb
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion tests/types/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,45 @@ def test_init():
assert array.attrs == attrs | {"datatype": "array<1>{real}"}


def test_resize():
def test_resize_and_capacity():
array = Array(nda=np.array([1, 2, 3, 4]))
assert array.get_capacity() == 4

array.resize(3)
assert array.get_capacity() == 4
assert (array.nda == np.array([1, 2, 3])).all()

array.resize(5)
assert array.get_capacity() >= 5

array.clear(trim=True)
assert array.get_capacity() == 0
assert len(array) == 0


def test_insert():
a = Array(np.array([1, 2, 3, 4]))
a.insert(2, [-1, -1])
assert a == Array([1, 2, -1, -1, 3, 4])

with pytest.raises(IndexError):
a.insert(10, 10)


def test_append():
a = Array(np.array([1, 2, 3, 4]))
a.append(-1)
assert a == Array([1, 2, 3, 4, -1])


def test_replace():
a = Array(np.array([1, 2, 3, 4]))
a.replace(2, -1)
assert a == Array([1, 2, -1, 4])

with pytest.raises(IndexError):
a.replace(10, 10)


def test_view():
a = Array(np.array([1, 2, 3, 4]), attrs={"units": "m"})
Expand Down

0 comments on commit 0a0bffb

Please sign in to comment.