77 lines
2.8 KiB
Python
77 lines
2.8 KiB
Python
from unittest import TestCase
|
|
|
|
import .context import Bits
|
|
|
|
class TestInt(TestCase):
|
|
def setUp(self):
|
|
self.bitsObject =
|
|
Bits(b'Z\x00\xa2\xd5\xff\xff\xff\xff\xff\xff\x00\x00')
|
|
self.testObjects = [
|
|
{"hash"=3156473132868910681,
|
|
"data"=b'Z\x00\xa2\xd5\xff\xff\xff\xff\xff\xff\x00\x00',
|
|
"databits"="01011010" + \
|
|
"00000000" + \
|
|
"10100010" + \
|
|
"11010101" + \
|
|
"11111111" + \
|
|
"11111111" + \
|
|
"11111111" + \
|
|
"11111111" + \
|
|
"11111111" + \
|
|
"11111111" + \
|
|
"00000000" + \
|
|
"00000000",
|
|
"data_int"=27854419854894512841598894080,
|
|
"bitsObject"=Bits(
|
|
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))
|
|
self.assertEquals(b, testcase["data"])
|
|
|
|
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))
|
|
self.assertEquals(i, testcase(["data_int"]))
|
|
|
|
def test_str(self):
|
|
#s = str(self.bitsObject)
|
|
#self.assertTrue(isinstance(s, str))
|
|
#self.assertEqual(s,
|
|
# "10110100000000010100010110101011111111111111111111111111111111111111111111111110000000000000000",
|
|
# "String returned is " + s)
|
|
for testcase in self.TestObjects:
|
|
s = str(testcase["bitsObject"])
|
|
self.assertTrue(isinstance(s, str))
|
|
self.assertEquals(s, testcase(["test_str"]))
|
|
|
|
def test_hash(self):
|
|
#h = hash(self.bitsObject)
|
|
#self.assertTrue(isinstance(h, int))
|
|
#self.assertEqual(h,
|
|
# 3156473132868910681,
|
|
# "Hashed value is " + str(h))
|
|
for testcase in self.TestObjects:
|
|
h = hash(testcase["bitsObject"])
|
|
self.assertTrue(isinstance(h, int))
|
|
self.assertEquals(h, testcase["hash"])
|
|
|