mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2025-06-12 21:07:13 +02:00
Adding patterntools to slsdet (#1142)
* added patterntools from mythen3tools * refactored do use implementation from slsSupportLib
This commit is contained in:
50
python/tests/test_bits.py
Normal file
50
python/tests/test_bits.py
Normal file
@ -0,0 +1,50 @@
|
||||
from slsdet.bits import clearbit, clearbit_arr, setbit, setbit_arr
|
||||
import numpy as np
|
||||
|
||||
|
||||
def test_clearbit_on_python_int():
|
||||
val = 5 # 0b101
|
||||
r = clearbit(0, val)
|
||||
assert r == 4
|
||||
assert val == 5
|
||||
|
||||
def test_setbit_on_python_int():
|
||||
val = 5 # 0b101
|
||||
r = setbit(1, val)
|
||||
assert r == 7
|
||||
assert val == 5
|
||||
|
||||
|
||||
def test_setbit_doesnt_change_type():
|
||||
word = np.int32(5)
|
||||
ret = setbit(0, word)
|
||||
assert isinstance(ret, np.int32)
|
||||
|
||||
|
||||
def test_clearbit_doesnt_change_type():
|
||||
word = np.uint8(5)
|
||||
ret = clearbit(0, word)
|
||||
assert isinstance(ret, np.uint8)
|
||||
|
||||
|
||||
|
||||
def test_setbit_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_setbit_arr():
|
||||
arr = np.zeros(10, dtype=np.int32)
|
||||
setbit_arr(3, arr[3:9])
|
||||
assert all(arr == np.array((0, 0, 0, 8, 8, 8, 8, 8, 8, 0), dtype=np.int32))
|
||||
|
||||
|
||||
def test_clearbit_arr():
|
||||
arr = np.array((5, 5, 5), dtype=np.int8)
|
||||
clearbit_arr(0, arr)
|
||||
assert all(arr == (4, 4, 4))
|
Reference in New Issue
Block a user