mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-07 10:32:25 +02:00
add flipbit tests
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
from slsdet.bits import clearbit, setbit
|
||||
from slsdet.bits import clearbit, setbit, flipbit
|
||||
from slsdet import RegisterAddress
|
||||
import numpy as np
|
||||
|
||||
@@ -15,6 +15,14 @@ def test_setbit_on_python_int():
|
||||
assert r == 7
|
||||
assert val == 5
|
||||
|
||||
def test_flipbit_on_python_int():
|
||||
val = 5 # 0b101
|
||||
r = flipbit(0, val)
|
||||
assert r == 4
|
||||
r2 = flipbit(1, val)
|
||||
assert r2 == 7
|
||||
assert val == 5
|
||||
|
||||
def test_setbit_doesnt_change_type():
|
||||
word = np.int32(5)
|
||||
ret = setbit(0, word)
|
||||
@@ -42,11 +50,34 @@ def test_setbit_array():
|
||||
test_array[9] = setbit(3, test_array[9])
|
||||
assert all(test_array == np.array((1, 1, 1, 2, 2, 2, 4, 4, 4, 8), dtype=np.int32))
|
||||
|
||||
def test_clearbit_on_array_element():
|
||||
arr = np.zeros(10, dtype=np.uint64)
|
||||
arr[5] = setbit(0, arr[5])
|
||||
arr[5] = setbit(1, arr[5])
|
||||
arr[5] = setbit(4, arr[5])
|
||||
assert arr[4] == 0
|
||||
assert arr[5] == 19 # 0b10011
|
||||
assert arr[6] == 0
|
||||
|
||||
def test_clearbit_array():
|
||||
test_array = 5*np.ones(3, dtype=np.int8)
|
||||
test_array[:] = clearbit(0, test_array)
|
||||
assert all(test_array == 4)
|
||||
|
||||
def test_flipbit_on_array_element():
|
||||
arr = 5*np.ones(10, dtype=np.uint64) # 0b101
|
||||
arr[5] = flipbit(0, arr[5])
|
||||
arr[5] = flipbit(1, arr[5])
|
||||
arr[5] = flipbit(2, arr[5])
|
||||
assert arr[4] == 5
|
||||
assert arr[5] == 2 # 0b010
|
||||
assert arr[6] == 5
|
||||
|
||||
def test_flipbit_array():
|
||||
test_array = 7*np.ones(3, dtype=np.int8) # 0b111
|
||||
test_array[:] = flipbit(0, test_array)
|
||||
assert all(test_array == 6) # 0b110
|
||||
|
||||
def test_RegisterAddress_addition():
|
||||
r = RegisterAddress(0x10)
|
||||
r2 = r + 0x5
|
||||
|
||||
Reference in New Issue
Block a user