Skip to content

Commit

Permalink
refactored format test cases to be more succinct
Browse files Browse the repository at this point in the history
  • Loading branch information
eredden committed Feb 8, 2025
1 parent 0e4f2fd commit 212b00e
Showing 1 changed file with 23 additions and 19 deletions.
42 changes: 23 additions & 19 deletions tests/test_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,19 @@ def test_get_timestamp(self):
"""
Verify that get_timestamp() correctly extracts timestamps from command output.
"""

outputs = [
"240626210300",
"230525200300",
"220424190300"
]

expected = [
{"year": 24, "month": 6, "day": 26, "hour": 21, "minute": 3},
{"year": 23, "month": 5, "day": 25, "hour": 20, "minute": 3},
{"year": 22, "month": 4, "day": 24, "hour": 19, "minute": 3}
# Cases are tuples with unformatted timestamps and formatted timestamps.
cases = [
("240626210300", {"year": 24, "month": 6, "day": 26, "hour": 21, "minute": 3}),
("230525200300", {"year": 23, "month": 5, "day": 25, "hour": 20, "minute": 3}),
("220424190300", {"year": 22, "month": 4, "day": 24, "hour": 19, "minute": 3})
]

for index in range(0, len(outputs)):
actual = _get_timestamp(outputs[index])
self.assertEqual(actual, expected[index])
for case in cases:
actual = _get_timestamp(case[0])
expected = case[1]

self.assertEqual(actual, expected)


def test_split_data(self):
"""
Expand Down Expand Up @@ -55,12 +52,19 @@ def test_hex_to_float(self):
Verify that hex_to_float() correctly makes IEEE floats from hexadecimal codes.
"""

hex_codes = ["3F800000", "B8D1B717", "C2C7FAE1", "461C4000"]
expected = [ 1.0, -0.0001, -99.99, 10000.0]
# Cases are tuples with a hexadecimal float and the equivalent decimal float.
cases = [
("3F800000", 1.0),
("B8D1B717", -0.0001),
("C2C7FAE1", -99.99),
("461C4000", 10000.0)
]

for index in range(0, len(hex_codes)):
actual = _hex_to_float(hex_codes[index])
self.assertEqual(actual, expected[index])
for case in cases:
actual = _hex_to_float(case[0])
expected = case[1]

self.assertEqual(actual, expected)

if __name__ == "__main__":
unittest.main()

0 comments on commit 212b00e

Please # to comment.