Skip to content

Commit

Permalink
Extend tests to 24bit types
Browse files Browse the repository at this point in the history
Signed-off-by: Greter Raffael <[email protected]>
  • Loading branch information
raffi-g committed Nov 28, 2023
1 parent f0bdfa6 commit 02b0712
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
7 changes: 7 additions & 0 deletions test/test_eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ class TestEDS(unittest.TestCase):
{"hex_str": "0000", "bit_length": 16, "expected": 0},
{"hex_str": "0001", "bit_length": 16, "expected": 1}
],
"int24": [
{"hex_str": "7FFFFF", "bit_length": 24, "expected": 8388607},
{"hex_str": "800000", "bit_length": 24, "expected": -8388608},
{"hex_str": "FFFFFF", "bit_length": 24, "expected": -1},
{"hex_str": "000000", "bit_length": 24, "expected": 0},
{"hex_str": "000001", "bit_length": 24, "expected": 1}
],
"int32": [
{"hex_str": "7FFFFFFF", "bit_length": 32, "expected": 2147483647},
{"hex_str": "80000000", "bit_length": 32, "expected": -2147483648},
Expand Down
14 changes: 14 additions & 0 deletions test/test_od.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ def test_unsigned16(self):
self.assertEqual(var.decode_raw(b"\xfe\xff"), 65534)
self.assertEqual(var.encode_raw(65534), b"\xfe\xff")

def test_unsigned24(self):
var = od.ODVariable("Test UNSIGNED24", 0x1000)
var.data_type = od.UNSIGNED24
self.assertEqual(var.decode_raw(b"\xfd\xfe\xff"), 16776957)
self.assertEqual(var.encode_raw(16776957), b"\xfd\xfe\xff")

def test_unsigned32(self):
var = od.ODVariable("Test UNSIGNED32", 0x1000)
var.data_type = od.UNSIGNED32
Expand All @@ -46,6 +52,14 @@ def test_integer16(self):
self.assertEqual(var.encode_raw(-2), b"\xfe\xff")
self.assertEqual(var.encode_raw(1), b"\x01\x00")

def test_integer24(self):
var = od.ODVariable("Test INTEGER24", 0x1000)
var.data_type = od.INTEGER24
self.assertEqual(var.decode_raw(b"\xfe\xff\xff"), -2)
self.assertEqual(var.decode_raw(b"\x01\x00\x00"), 1)
self.assertEqual(var.encode_raw(-2), b"\xfe\xff\xff")
self.assertEqual(var.encode_raw(1), b"\x01\x00\x00")

def test_integer32(self):
var = od.ODVariable("Test INTEGER32", 0x1000)
var.data_type = od.INTEGER32
Expand Down

0 comments on commit 02b0712

Please sign in to comment.