generated from Coding-Cuddles/bootstrap-python-kata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
127 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
class BitConverter: | ||
|
||
@staticmethod | ||
def get_bytes(value): | ||
"""Convert an integer to a list of integers representing bytes.""" | ||
return list(value.to_bytes((value.bit_length() + 7) // 8, "little")) | ||
|
||
@staticmethod | ||
def to_int(byte_list): | ||
"""Convert a list of integers representing bytes to an integer.""" | ||
return int.from_bytes(bytes(byte_list), "little") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from bit_converter import BitConverter | ||
|
||
|
||
class TelemetryBuffer: | ||
|
||
@classmethod | ||
def to_buffer(cls, reading: int) -> list[int]: | ||
return [0x2] + BitConverter.get_bytes(reading) + [0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0] |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from telemetry_buffer import TelemetryBuffer | ||
|
||
|
||
class TestToBuffer: | ||
|
||
def test_unsigned_short(self): | ||
expected = [0x2, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0] | ||
assert TelemetryBuffer.to_buffer(5) == expected |