Skip to content

Commit 2a35b9b

Browse files
committed
Improved tests for from_text methods
1 parent ba94991 commit 2a35b9b

3 files changed

Lines changed: 12 additions & 0 deletions

File tree

‎tests/test_half_vector.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def test_from_text(self) -> None:
6767
assert np.array_equal(vec.to_numpy(), [1.5, 2, 3])
6868
assert vec.to_text() == '[1.5,2.0,3.0]'
6969

70+
def test_from_text_zero_length(self) -> None:
71+
with pytest.raises(ValueError, match='could not convert string to float'):
72+
HalfVector.from_text('')
73+
7074
def test_from_text_zero_dimensions(self) -> None:
7175
assert HalfVector.from_text('[]') == HalfVector([])
7276

‎tests/test_sparse_vector.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,10 @@ def test_from_text(self) -> None:
169169
assert np.array_equal(vec.to_numpy(), [1.5, 0, 2, 0, 3, 0])
170170
assert vec.to_text() == '{1:1.5,3:2.0,5:3.0}/6'
171171

172+
def test_from_text_zero_length(self) -> None:
173+
with pytest.raises(ValueError, match='not enough values to unpack'):
174+
SparseVector.from_text('')
175+
172176
def test_from_text_zero_dimensions(self) -> None:
173177
assert SparseVector.from_text('{}/0') == SparseVector([])
174178

‎tests/test_vector.py‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ def test_from_text(self) -> None:
6767
assert np.array_equal(vec.to_numpy(), [1.5, 2, 3])
6868
assert vec.to_text() == '[1.5,2.0,3.0]'
6969

70+
def test_from_text_zero_length(self) -> None:
71+
with pytest.raises(ValueError, match='could not convert string to float'):
72+
Vector.from_text('')
73+
7074
def test_from_text_zero_dimensions(self) -> None:
7175
assert Vector.from_text('[]') == Vector([])
7276

0 commit comments

Comments
 (0)