Coverage for /home/jenkins/workspace/NDS/Zserio/NDS_ZSERIO-linux-build/compiler/extensions/python/runtime/tests/test_bitposition.py: 100%
34 statements
« prev ^ index » next coverage.py v6.5.0, created at 2023-12-13 15:12 +0000
« prev ^ index » next coverage.py v6.5.0, created at 2023-12-13 15:12 +0000
1import unittest
3from zserio.bitposition import (alignto, bits_to_bytes, bytes_to_bits, bitsize_to_bytesize)
4from zserio.exception import PythonRuntimeException
6class BitPositionTest(unittest.TestCase):
8 def test_alignto(self):
9 bitposition = 5
10 self.assertEqual(5, alignto(0, bitposition))
11 self.assertEqual(5, alignto(1, bitposition))
12 self.assertEqual(6, alignto(2, bitposition))
13 self.assertEqual(6, alignto(3, bitposition))
14 self.assertEqual(8, alignto(4, bitposition))
15 self.assertEqual(5, alignto(5, bitposition))
16 self.assertEqual(6, alignto(6, bitposition))
17 self.assertEqual(7, alignto(7, bitposition))
18 self.assertEqual(8, alignto(8, bitposition))
20 def test_bits_to_bytes(self):
21 self.assertEqual(1, bits_to_bytes(8))
22 self.assertEqual(3, bits_to_bytes(24))
23 with self.assertRaises(PythonRuntimeException):
24 bits_to_bytes(4)
25 with self.assertRaises(PythonRuntimeException):
26 bits_to_bytes(9)
28 def test_bytes_to_bits(self):
29 self.assertEqual(0, bytes_to_bits(0))
30 self.assertEqual(8, bytes_to_bits(1))
31 self.assertEqual(16, bytes_to_bits(2))
33 def test_bitsize_to_bytesize(self):
34 self.assertEqual(0, bitsize_to_bytesize(0))
35 self.assertEqual(1, bitsize_to_bytesize(4))
36 self.assertEqual(1, bitsize_to_bytesize(8))
37 self.assertEqual(2, bitsize_to_bytesize(9))
38 self.assertEqual(2, bitsize_to_bytesize(16))
39 self.assertEqual(3, bitsize_to_bytesize(17))
40 self.assertEqual(3, bitsize_to_bytesize(24))