diff --git a/tests/test_bytes.py b/tests/test_bytes.py new file mode 100644 index 0000000..b97c4d7 --- /dev/null +++ b/tests/test_bytes.py @@ -0,0 +1,72 @@ +from unittest import TestCase + +from .context import Bytes + +class TestBytes(TestCase): + def setUp(self): + pass + + def test_init(self): + """ + Test creation of Bytes object + """ + self.assertIsInstance(Bytes(b'abc'), Bytes, + "bytes: Bytes(b'abc') is Type(Bytes)") + self.assertIsInstance(Bytes(1234), Bytes, + "int: Bytes(1234) is Type(Bytes)") + self.assertIsInstance(Bytes("01010101110101"), Bytes, + "str: Bytes(\"01010101110101\") is Type(Bytes)") + self.assertIsInstance(Bytes(Bytes(1234)), Bytes, + "Bytes: Bytes(Bytes(1234)) is Type(Bytes)") + self.assertIsInstance(Bytes([True] * 30), Bytes, + "list (of bool): " + "Bytes([True] * 30) is Type(Bytes)") + self.assertIsInstance(Bytes([Bits(127)] * 30), Bytes, + "list (of Bits): " + "Bytes([Bits(127)] * 30) is Type(Bytes)") + self.assertIsInstance(Bytes([Bit(True)] * 30), Bytes, + "list (of bit): " + "Bytes([Bit(True)] * 30) is Type(Bytes)") + with self.assertRaises(TypeError, "Bytes(\"1234\")"): + Bytes("1234") + with self.assertRaises(ValueError, "Bytes(-1234)"): + Bytes(-1234) + + def test_comparison_operators(self): + """ + Test the comparison operators with Bytes objects + """ + with self.subTest("int Type"): + self.assertEqual(Bytes(1234), 1234, + "Bytes(1234) == 1234") + self.assertNotEqual(Bytes(1234), 4321, + "Bytes(1234) != 4321") + self.assertEqual(5678, Bytes(5678), + "5678 == Bytes(5678)") + self.assertNotEqual(8765, Bytes(5678), + "8765 != Bytes(5678)") + self.assertLess(Bytes(123), 128, + "Bytes(123) < 128") + self.assertLessEqual(Bytes(124), 125, + "Bytes(124) <= 125") + self.assertLessEqual(Bytes(125), 125, + "Bytes(125) <= 125") + self.assertGreater(Bytes(255), 128, + "Bytes(255) > 128") + self.assertGreaterEqual(Bytes(256), 255, + "Bytes(256) >= 255") + self.assertGreaterEqual(Bytes(512), 512, + "Bytes(512) >= 512") + self.assertLess(123, Bytes(125), + "123 < Bytes(125)") + self.assertlessEqual(1024, Bytes(2048), + "1024 <= Bytes(2048)") + self.assertLessEqual(4092, Bytes(4092), + "4092 <= Bytes(4092)") + self.assertGreater(499, Bytes(200), + "499 > Bytes(200)") + self.assertGreaterEqual(322, Bytes(122), + "322 >= Bytes(122)") + self.assertGreaterEqual(510, Bytes(510), + "510 >= Bytes(510)") +