Skip to content

Commit 31c4a94

Browse files
committed
Added tests for from_text and from_binary for Bit
1 parent 7002b0f commit 31c4a94

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

tests/test_bit.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from pgvector import Bit
22
import pytest
33
import random
4+
from struct import pack
45

56
try:
67
import numpy as np
@@ -81,3 +82,17 @@ def test_repr(self) -> None:
8182
def test_equality(self) -> None:
8283
assert Bit([True, False, True]) == Bit([True, False, True])
8384
assert Bit([True, False, True]) != Bit([True, False, False])
85+
86+
def test_from_text(self) -> None:
87+
vec = Bit.from_text('101')
88+
assert vec.to_list() == [True, False, True]
89+
if NUMPY_AVAILABLE:
90+
assert np.array_equal(vec.to_numpy(), [True, False, True])
91+
92+
def test_from_binary(self) -> None:
93+
data = pack('>iB', 3, 5 << 5)
94+
vec = Bit.from_binary(data)
95+
assert vec.to_list() == [True, False, True]
96+
if NUMPY_AVAILABLE:
97+
assert np.array_equal(vec.to_numpy(), [True, False, True])
98+
assert vec.to_binary() == data

0 commit comments

Comments
 (0)