summaryrefslogtreecommitdiff
path: root/stacks/crdop/lib/test_bell202_line_code.py
diff options
context:
space:
mode:
authorinfo@mode42.com <info@mode42.com>2026-08-07 18:25:13 +0000
committerinfo@mode42.com <info@mode42.com>2026-08-07 18:25:13 +0000
commit04d965d67a7264a1c7c211494aebda1953df7603 (patch)
tree0ebd700a6e219f84a26a656f4bee8778bc75da7b /stacks/crdop/lib/test_bell202_line_code.py
Initial push
Diffstat (limited to 'stacks/crdop/lib/test_bell202_line_code.py')
-rw-r--r--stacks/crdop/lib/test_bell202_line_code.py34
1 files changed, 34 insertions, 0 deletions
diff --git a/stacks/crdop/lib/test_bell202_line_code.py b/stacks/crdop/lib/test_bell202_line_code.py
new file mode 100644
index 0000000..3b22af6
--- /dev/null
+++ b/stacks/crdop/lib/test_bell202_line_code.py
@@ -0,0 +1,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())
git clone -b <branch> https://cgit.mode42.com/<repo>.git
git clone -b <branch> git://cgit.mode42.com/<repo>.git

info@mode42.com