-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathtest_bit.py
More file actions
47 lines (36 loc) · 1.54 KB
/
test_bit.py
File metadata and controls
47 lines (36 loc) · 1.54 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import numpy as np
from pgvector import Bit
import pytest
class TestBit:
def test_list(self):
assert Bit([True, False, True]).to_list() == [True, False, True]
def test_tuple(self):
assert Bit((True, False, True)).to_list() == [True, False, True]
def test_str(self):
assert Bit('101').to_list() == [True, False, True]
def test_ndarray_uint8(self):
arr = np.array([254, 7, 0], dtype=np.uint8)
assert Bit(arr).to_text() == '111111100000011100000000'
def test_ndarray_uint16(self):
arr = np.array([254, 7, 0], dtype=np.uint16)
with pytest.raises(ValueError) as error:
Bit(arr)
assert str(error.value) == 'expected dtype to be bool or uint8'
def test_ndarray_same_object(self):
arr = np.array([True, False, True])
assert Bit(arr).to_list() == [True, False, True]
assert Bit(arr).to_numpy() is arr
def test_ndim_two(self):
with pytest.raises(ValueError) as error:
Bit([[True, False], [True, False]])
assert str(error.value) == 'expected ndim to be 1'
def test_ndim_zero(self):
with pytest.raises(ValueError) as error:
Bit(True)
assert str(error.value) == 'expected ndim to be 1'
def test_repr(self):
assert repr(Bit([True, False, True])) == 'Bit(101)'
assert str(Bit([True, False, True])) == 'Bit(101)'
def test_equality(self):
assert Bit([True, False, True]) == Bit([True, False, True])
assert Bit([True, False, True]) != Bit([True, False, False])