python: Add bhash tests

This commit is contained in:
2021-09-28 09:57:33 +02:00
parent 3852c4efc9
commit 52935bc765
2 changed files with 27 additions and 0 deletions

23
tests/test_bhash.py Executable file
View File

@ -0,0 +1,23 @@
#!/usr/bin/env python3
import passgeny.bhash
import sys
TEST_STRING = b'hello world'
bh = passgeny.bhash.Bhash()
bh.from_bytes(TEST_STRING)
# Scan the string in reverse order (::-1) as bhash should use big endian arithmetics
for c in TEST_STRING[::-1]:
hc = bh.modulo(256)
if hc != c:
raise Exception("Returned value is {}, expected {}".format(chr(hc), c))
# This should throw an exception as we consumned all the bits in bhash
try:
bh.modulo(2)
except passgeny.bhash.BhashException as e:
print("Properly received exception: {}".format(e))
else:
raise Exception("Did not receive BhashException.")