bits/tests/test_bits.py

77 lines
2.8 KiB
Python
Raw Normal View History

2020-10-03 20:35:46 -05:00
from unittest import TestCase
2020-10-04 13:11:46 -05:00
from .context import Bits
2020-10-03 20:35:46 -05:00
class TestInt(TestCase):
def setUp(self):
2020-10-04 13:11:46 -05:00
self.bitsObject = \
Bits(b'Z\x00\xa2\xd5\xff\xff\xff\xff\xff\xff\x00\x00')
2020-10-03 20:35:46 -05:00
self.testObjects = [
2020-10-04 13:11:46 -05:00
{"hash": -3172158928563556465,
"data": b'Z\x00\xa2\xd5\xff\xff\xff\xff\xff\xff\x00\x00',
"databits": "1011010" + \
2020-10-03 20:35:46 -05:00
"00000000" + \
"10100010" + \
"11010101" + \
"11111111" + \
"11111111" + \
"11111111" + \
"11111111" + \
"11111111" + \
"11111111" + \
"00000000" + \
"00000000",
2020-10-04 13:11:46 -05:00
"data_int": 27854419854894512841598894080,
"bitsObject": Bits(
2020-10-03 20:35:46 -05:00
b'Z\x00\xa2\xd5\xff\xff\xff\xff\xff\xff\x00\x00'
)
}
]
def test_bytes(self):
# b = bytes(self.bitsObject)
# self.assertTrue(isinstance(b, bytes))
#self.assertEquals(b,
# b'Z\x00\xa2\xd5\xff\xff\xff\xff\xff\xff\x00\x00',
# "Bytes object returned is :" + b)
for testcase in self.testObjects:
b = bytes(testcase["bitsObject"])
self.assertTrue(isinstance(b, bytes))
2020-10-04 13:11:46 -05:00
self.assertEqual(b, testcase["data"])
2020-10-03 20:35:46 -05:00
def test_int(self):
#i = int(thebits.bits(b'Z\x00\xa2\xd5\xff\xff\xff\xff\xff\xff\x00\x00'))
#i = int(self.bitsObject)
#self.assertTrue(isinstance(i, int))
#self.assertEqual(i,
# 27854419854894512841598894080,
# "Type is " + type(i)
# )
for testcase in self.testObjects:
i = int(testcase["bitsObject"])
self.assertTrue(isinstance(i, int))
2020-10-04 13:11:46 -05:00
self.assertEqual(i, testcase["data_int"])
2020-10-03 20:35:46 -05:00
def test_str(self):
#s = str(self.bitsObject)
#self.assertTrue(isinstance(s, str))
#self.assertEqual(s,
# "10110100000000010100010110101011111111111111111111111111111111111111111111111110000000000000000",
# "String returned is " + s)
2020-10-04 13:11:46 -05:00
for testcase in self.testObjects:
2020-10-03 20:35:46 -05:00
s = str(testcase["bitsObject"])
self.assertTrue(isinstance(s, str))
2020-10-04 13:11:46 -05:00
self.assertEqual(s, testcase["databits"])
2020-10-03 20:35:46 -05:00
def test_hash(self):
#h = hash(self.bitsObject)
#self.assertTrue(isinstance(h, int))
#self.assertEqual(h,
# 3156473132868910681,
# "Hashed value is " + str(h))
2020-10-04 13:11:46 -05:00
for testcase in self.testObjects:
2020-10-03 20:35:46 -05:00
h = hash(testcase["bitsObject"])
self.assertTrue(isinstance(h, int))
2020-10-04 13:11:46 -05:00
self.assertEqual(h, testcase["hash"])
2020-10-03 20:35:46 -05:00