topos.functors.profunctors.uast.structural_test_coverage

Structural test coverage (UAST)

PUT-directed recall: how much of the program-under-test’s UAST structure is represented in the test suite’s UAST, using kind histograms, control-flow profiles, and optional k-gram path overlap.

topos.functors.profunctors.uast.structural_test_coverage.merge_uast_kind_histograms(roots, *, include_unknown=False)[source]

Sum uast_kind_histogram across multiple UAST roots.

topos.functors.profunctors.uast.structural_test_coverage.merge_control_flow_profiles(roots)[source]

Sum control_flow_profile across multiple UAST roots.

topos.functors.profunctors.uast.structural_test_coverage.merge_kgram_counters(roots, *, k, include_unknown=False)[source]

Multiset of length-k kind n-grams, aggregated per root then summed.

Each root is DFS-sequenced independently; k-grams never span file boundaries.

topos.functors.profunctors.uast.structural_test_coverage.extract_declarations(root)[source]

Return all FunctionDecl/MethodDecl UASTNodes via DFS (includes nested).

class topos.functors.profunctors.uast.structural_test_coverage.DeclarationCoverageReport(mean_declaration_coverage, best_declaration_recall, declaration_locations, stmt_recall, expr_recall, mean_test_precision, declaration_path_recall_kgram, k, put_declaration_count, test_declaration_count, include_unknown)[source]

Bases: object

Declaration-level bipartite structural coverage.

Each FunctionDecl/MethodDecl in the PUT is matched against the test suite’s declarations via greedy best-match recall. Scores are not inflated by adding unrelated test code (not monotone with corpus size).

mean_declaration_coverage
best_declaration_recall
declaration_locations
stmt_recall
expr_recall
mean_test_precision
declaration_path_recall_kgram
k
put_declaration_count
test_declaration_count
include_unknown
property declaration_coverage_rate

Alias for mean_declaration_coverage (backward compatibility).

property f2_score

F2 score favoring recall over precision.

property uncovered_declarations

Locations of PUT declarations with incomplete test coverage.

topos.functors.profunctors.uast.structural_test_coverage.declaration_coverage(put_roots, test_roots, *, k=3, include_unknown=False)[source]

Declaration-level bipartite structural coverage.

For each FunctionDecl/MethodDecl in the PUT, finds the best-matching test declaration by multiset recall of body kind histograms. Addresses the five weaknesses of earlier metrics:

  • Pooled histograms replaced by per-declaration matching (localizable gaps)

  • CF/kind double-counting replaced by disjoint stmt/expr category recall

  • DFS k-grams scoped to declaration subtrees (semantically bounded)

  • Not monotone: unrelated test functions do not inflate PUT coverage

  • Precision signal added: F2 score penalizes bloated test suites

Parameters:
  • put_roots – One or more UAST roots for the program-under-test.

  • test_roots – Zero or more UAST roots for the test suite.

  • k – Length of each kind n-gram for declaration_path_recall_kgram.

  • include_unknown – Whether to include Unknown kinds.

Returns:

DeclarationCoverageReport. Vacuous PUT (no declarations) yields 1.0 for all recall scores with put_declaration_count = 0.