BioSight/python/phi/test_phi.py
allaun e0b2283972 feat(phi): full docstring + verification hardening pass
Every function in all 5 phi modules now has:
- Google-style docstring with Args/Returns/Examples
- Verified behavior via doctest examples (46 total)
- Self-verification assertion blocks on direct execution

Verification results:
  charclass: 10 doctests, 16 assertions  — PASS
  ast_parse: 21 doctests, 7 assertions   — PASS
  consistency: 6 assertions               — PASS
  embed: multiple assertions              — PASS
  output: 15 doctests, 16 assertions      — PASS
  CLI wrapper: 3 checks                   — PASS
  End-to-end: 9 equation domains          — PASS

Also added:
- .opencode/opencode.jsonc (gemma4 MCP config)
- phi/AGENTS.md (module-level contract)
- phi/test_phi.py (unittest test file)
- phi/encoding_rationale.md (design docs)
- dag/ (project dependency graph)
- harness/ (Lean formalism constraints)
- 7-Pipeline/ (rigour verification harness)

Build: python3 -W error -m py_compile — 0 warnings
2026-06-24 03:57:50 -05:00

42 lines
1.2 KiB
Python

import sys
import os
# Add current directory to path so we can import from . (or just use module names)
sys.path.append(os.path.dirname(__file__))
from phi.embed import encode_phi
from phi.output import to_fastq, design_filtering_protocol
def test():
equations = [
"x + y",
"(a * b) + (c / d)",
"x^2 + y^2 = z^2",
"sin(x) + cos(y)",
"sqrt(x + y) * 2",
"", # Empty case
]
print(f"{'Equation':<20} | {'DNA Sequence':<30} | {'Consistency Pass':<15}")
print("-" * 70)
for eq in equations:
record = encode_phi(eq)
if record:
dna = record["dna_sequence"]
pass_flag = "PASS" if record["consistency_pass"] else "FAIL"
print(f"{eq:<20} | {dna:<30} | {pass_flag:<15}")
else:
print(f"{eq:<20} | {'None':<30} | {'N/A':<15}")
# Test Output functions
sample_record = encode_phi("(a + b) * c")
if sample_record:
print("\n--- FASTQ Example ---")
print(to_fastq(sample_record))
print("--- PCR Protocol ---")
print(design_filtering_protocol([sample_record]))
if __name__ == "__main__":
test()