From 02b0712c3c9ed794ea35a581e25a8cd67d2180a8 Mon Sep 17 00:00:00 2001 From: Greter Raffael Date: Tue, 21 Nov 2023 14:42:29 +0100 Subject: [PATCH] Extend tests to 24bit types Signed-off-by: Greter Raffael --- test/test_eds.py | 7 +++++++ test/test_od.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/test/test_eds.py b/test/test_eds.py index a3923709..a35cbb99 100644 --- a/test/test_eds.py +++ b/test/test_eds.py @@ -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}, diff --git a/test/test_od.py b/test/test_od.py index fe90dc13..a5f00985 100644 --- a/test/test_od.py +++ b/test/test_od.py @@ -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 @@ -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