blob: 3b22af68586effd95576ae51d30eb75a28d180ae (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
#!/usr/bin/env python3
"""Unit tests for Bell 202 frequency-toggle line code."""
from __future__ import annotations
import sys
from pathlib import Path
LIB = Path(__file__).resolve().parent
sys.path.insert(0, str(LIB))
from bell202_line_code import decode_tones_to_bits, encode_bits_to_tones # noqa: E402
def test_roundtrip_single_byte() -> None:
bits = bytes([0x55]) # 01010101 → many toggles
tones = encode_bits_to_tones(bits, start_tone=0)
back = decode_tones_to_bits(tones, start_tone=0)
assert back == bits
def test_all_ones_no_toggle() -> None:
tones = encode_bits_to_tones(bytes([0xFF]), start_tone=0)
assert len(set(tones)) == 1
def main() -> int:
test_roundtrip_single_byte()
test_all_ones_no_toggle()
print("OK: bell202_line_code tests")
return 0
if __name__ == "__main__":
raise SystemExit(main())
|