"""Test UCC-compatible counting engine. Verifies that the Python port produces identical results to original UCC. """ from pathlib import Path import sys sys.path.insert(0, str(Path(__file__).parent.parent)) from pyucc.core.ucc_compat_counting import analyze_file_ucc_compatible def test_ucc_compat(): """Test UCC-compatible counting on real file.""" test_file = Path(r"C:\__temp\Metrics\attuale\REP\Projects\DSP\ChimeraMCK\dev\mck_c66\mck_c66_boot_multicore.c") if not test_file.exists(): print("āš ļø Test file not found, using demo...") demo_ucc_compat() return print(f"Analyzing: {test_file.name}") print("=" * 80) result = analyze_file_ucc_compatible(test_file) print("\nšŸ PyUCC (UCC-Compatible Engine) Results:") print(f" Total Lines: {result['total_lines']:>6}") print(f" Blank Lines: {result['blank_lines']:>6}") print(f" Compiler Dir (Physical): {result['compiler_directives_phy']:>6}") print(f" Compiler Dir (Logical): {result['compiler_directives_log']:>6}") print(f" Data Decl (Physical): {result['data_declarations_phy']:>6}") print(f" Data Decl (Logical): {result['data_declarations_log']:>6}") print(f" Exec Inst (Physical): {result['exec_instructions_phy']:>6}") print(f" Exec Inst (Logical): {result['exec_instructions_log']:>6}") print(f" Logical SLOC (Total): {result['logical_sloc']:>6}") print(f" Physical SLOC (Total): {result['physical_sloc']:>6}") print("\n" + "=" * 80) print("šŸŽÆ UCC Expected Values (from original output):") print(f" Total Lines: {'402':>6}") print(f" Blank Lines: {'86':>6}") print(f" Compiler Dir (Logical): {'22':>6}") print(f" Data Decl (Logical): {'57':>6}") print(f" Exec Inst (Logical): {'127':>6}") print(f" Logical SLOC (Total): {'206':>6}") print(f" Physical SLOC (Total): {'271':>6}") print("\n" + "=" * 80) print("šŸ“Š Comparison:") print(f" Total: {result['total_lines'] - 402:>+6} (target: 0)") print(f" Blank: {result['blank_lines'] - 86:>+6} (target: 0)") print(f" Directive Log: {result['compiler_directives_log'] - 22:>+6} (target: 0)") print(f" Data Decl Log: {result['data_declarations_log'] - 57:>+6} (target: 0)") print(f" Exec Inst Log: {result['exec_instructions_log'] - 127:>+6} (target: 0)") print(f" Logical SLOC: {result['logical_sloc'] - 206:>+6} (target: 0)") print(f" Physical SLOC: {result['physical_sloc'] - 271:>+6} (target: 0)") # Calculate accuracy total_diff = abs(result['total_lines'] - 402) blank_diff = abs(result['blank_lines'] - 86) dir_diff = abs(result['compiler_directives_log'] - 22) data_diff = abs(result['data_declarations_log'] - 57) exec_diff = abs(result['exec_instructions_log'] - 127) lsloc_diff = abs(result['logical_sloc'] - 206) psloc_diff = abs(result['physical_sloc'] - 271) total_metrics = 7 perfect_matches = sum([ total_diff == 0, blank_diff == 0, dir_diff == 0, data_diff == 0, exec_diff == 0, lsloc_diff == 0, psloc_diff == 0 ]) accuracy = (perfect_matches / total_metrics) * 100 print(f"\nāœ… Perfect Matches: {perfect_matches}/{total_metrics} ({accuracy:.1f}%)") if accuracy == 100.0: print("\nšŸŽ‰ PERFECT! 100% match with UCC!") elif accuracy >= 85.0: print(f"\nāœ… GOOD! {accuracy:.1f}% accuracy - close to UCC") else: print(f"\nāš ļø NEEDS WORK: {accuracy:.1f}% accuracy") def demo_ucc_compat(): """Demo with simple code.""" import tempfile code = """// Demo file #include int main() { int x = 5; if (x > 0) { printf("positive"); } return 0; } """ with tempfile.NamedTemporaryFile(mode='w', suffix='.c', delete=False) as f: f.write(code) temp_path = Path(f.name) print("Testing with demo C code...") result = analyze_file_ucc_compatible(temp_path) print(f"\nResults:") print(f" Total Lines: {result['total_lines']}") print(f" Logical SLOC: {result['logical_sloc']}") print(f" Data Decl: {result['data_declarations_log']}") print(f" Exec Inst: {result['exec_instructions_log']}") temp_path.unlink() if __name__ == "__main__": test_ucc_compat()