mirror of
https://github.com/slsdetectorgroup/slsDetectorPackage.git
synced 2026-08-06 19:52:26 +02:00
fixed tests for new setbit, clearbit
This commit is contained in:
+12
-15
@@ -1,4 +1,4 @@
|
||||
from slsdet.bits import clearbit, clearbit_arr, setbit, setbit_arr
|
||||
from slsdet.bits import clearbit, setbit
|
||||
from slsdet import RegisterAddress
|
||||
import numpy as np
|
||||
|
||||
@@ -15,20 +15,16 @@ def test_setbit_on_python_int():
|
||||
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])
|
||||
@@ -38,17 +34,18 @@ def test_setbit_on_array_element():
|
||||
assert arr[5] == 19 # 0b10011
|
||||
assert arr[6] == 0
|
||||
|
||||
def test_setbit_array():
|
||||
test_array = np.zeros(10, dtype=np.int32)
|
||||
test_array[0:3] = setbit(0, test_array[0:3])
|
||||
test_array[3:6] = setbit(1, test_array[3:6])
|
||||
test_array[6:9] = setbit(2, test_array[6:9])
|
||||
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_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))
|
||||
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_RegisterAddress_addition():
|
||||
r = RegisterAddress(0x10)
|
||||
|
||||
Reference in New Issue
Block a user