forked from panda3d/panda3d
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_bitarray.py
More file actions
63 lines (44 loc) · 1.69 KB
/
test_bitarray.py
File metadata and controls
63 lines (44 loc) · 1.69 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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
from panda3d.core import BitArray
import pickle
import pytest
def test_bitarray_constructor():
assert BitArray().is_zero()
assert BitArray(0).is_zero()
ba = BitArray(0x10000000000000000000000000)
assert ba.get_lowest_on_bit() == 100
assert ba.get_highest_on_bit() == 100
with pytest.raises(Exception):
assert BitArray(-1)
with pytest.raises(Exception):
assert BitArray(-10000000000000000000)
def test_bitarray_allon():
assert BitArray.all_on().is_all_on()
def test_bitarray_nonzero():
assert not BitArray()
assert not BitArray(0)
assert BitArray(1)
assert BitArray.all_on()
def test_bitarray_invert():
assert ~BitArray(0) != BitArray(0)
assert (~BitArray(0)).is_all_on()
assert ~~BitArray(0) == BitArray(0)
assert ~~BitArray(123) == BitArray(123)
def test_bitarray_getstate():
assert BitArray().__getstate__() == 0
assert BitArray(0).__getstate__() == 0
assert BitArray(100).__getstate__() == 100
assert BitArray(9870000000000000000).__getstate__() == 9870000000000000000
assert BitArray.all_on().__getstate__() == -1
assert (~BitArray(100).__getstate__()) == ~100
assert (~BitArray(812000000000000000).__getstate__()) == ~812000000000000000
def test_bitarray_pickle():
ba = BitArray()
assert ba == pickle.loads(pickle.dumps(ba, -1))
ba = BitArray(0)
assert ba == pickle.loads(pickle.dumps(ba, -1))
ba = BitArray(123)
assert ba == pickle.loads(pickle.dumps(ba, -1))
ba = BitArray(94187049178237918273981729127381723)
assert ba == pickle.loads(pickle.dumps(ba, -1))
ba = ~BitArray(94187049178237918273981729127381723)
assert ba == pickle.loads(pickle.dumps(ba, -1))