add flipbit tests
Build on RHEL9 docker image / build (push) Successful in 4m20s
Build on RHEL8 docker image / build (push) Successful in 5m16s
Run Simulator Tests on local RHEL9 / build (push) Successful in 18m53s
Run Simulator Tests on local RHEL8 / build (push) Successful in 22m26s

This commit is contained in:
2026-07-20 09:57:57 +02:00
parent 5a5da09fcf
commit 88505017fa
+32 -1
View File
@@ -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