Skip to content

Commit e6edb2a

Browse files
committed
Improved tests [skip ci]
1 parent 340caa5 commit e6edb2a

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

tests/test_half_vector.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,8 @@ def test_equality(self):
4444

4545
def test_dimensions(self):
4646
assert HalfVector([1, 2, 3]).dimensions() == 3
47+
48+
def test_from_text(self):
49+
vec = HalfVector.from_text('[1.5,2,3]')
50+
assert vec.to_list() == [1.5, 2, 3]
51+
assert np.array_equal(vec.to_numpy(), np.array([1.5, 2, 3]))

tests/test_psycopg.py

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,6 @@ def test_halfvec_text_format(self):
8383
embedding = HalfVector([1.5, 2, 3])
8484
res = conn.execute('SELECT %t::halfvec', (embedding,)).fetchone()[0]
8585
assert res == HalfVector([1.5, 2, 3])
86-
# TODO move
87-
assert res.to_list() == [1.5, 2, 3]
88-
assert np.array_equal(res.to_numpy(), np.array([1.5, 2, 3]))
8986

9087
def test_bit(self):
9188
embedding = Bit([True, False, True])
@@ -127,12 +124,6 @@ def test_sparsevec_text_format(self):
127124
embedding = SparseVector([1.5, 0, 2, 0, 3, 0])
128125
res = conn.execute('SELECT %t::sparsevec', (embedding,)).fetchone()[0]
129126
assert res == embedding
130-
# TODO move
131-
assert res.dimensions() == 6
132-
assert res.indices() == [0, 2, 4]
133-
assert res.values() == [1.5, 2, 3]
134-
assert res.to_list() == [1.5, 0, 2, 0, 3, 0]
135-
assert np.array_equal(res.to_numpy(), np.array([1.5, 0, 2, 0, 3, 0]))
136127

137128
def test_text_copy_from(self):
138129
embedding = np.array([1.5, 2, 3])

tests/test_sparse_vector.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,11 @@ def test_to_coo(self):
7373
def test_zero_vector_text(self):
7474
vec = SparseVector({}, 3)
7575
assert vec.to_list() == SparseVector.from_text(vec.to_text()).to_list()
76+
77+
def test_from_text(self):
78+
vec = SparseVector.from_text('{1:1.5,3:2,5:3}/6')
79+
assert vec.dimensions() == 6
80+
assert vec.indices() == [0, 2, 4]
81+
assert vec.values() == [1.5, 2, 3]
82+
assert vec.to_list() == [1.5, 0, 2, 0, 3, 0]
83+
assert np.array_equal(vec.to_numpy(), np.array([1.5, 0, 2, 0, 3, 0]))

0 commit comments

Comments
 (0)