Testing Legal Code
Testing Legal Code
Unit, example, boundary, property, metamorphic, mutation, differential, regression, conformance, fuzz, temporal, provenance, explanation and human-review tests.
Structured Visual
Jurisdiction: US; as of 2026-08-28; not legal advice; Render structure, refuse interpretation, cite, abstain, and hand off.
RENDER STRUCTURE · REFUSE INTERPRETATION · CITE · ABSTAIN · HAND-OFF: render structure, refuse interpretation, cite provenance, abstain when unsupported, and hand off to human review.
Scope and honesty note
Jurisdiction: United States computational-law classroom model; source snapshot 2026-08-28; curriculum as of 2026-08-29. Synthetic inputs, code, labels, measurements and outputs are teaching artifacts, not law, legal advice, authority, eligibility, benefits, tax, court, filing, research, ranking, or outcome determinations. Code encodes selected interpretations and can be incomplete, wrong, outdated, biased, overprecise, underinclusive, or non-isomorphic. The system must cite source and version, expose assumptions and gaps, abstain when unsupported, and hand legal judgment to accountable humans.
See the essential structure first
Start with this deliberately incomplete structure, then use the pinned authorities, worked application, exceptions, and handoff below. This deliberately incomplete preview has 4 nodes; exceptions and legal consequences remain in the sourced prose below.
Jurisdiction: US; as of 2026-08-28; not legal advice; Render structure, refuse interpretation, cite, abstain, and hand off.
RENDER STRUCTURE · REFUSE INTERPRETATION · CITE · ABSTAIN · HAND-OFF: render structure, refuse interpretation, cite provenance, abstain when unsupported, and hand off to human review.
Begin with computational-law doctrine
Testing legal code must challenge semantics, not merely execute lines. Example and boundary tests cover known cases; property and metamorphic tests require defensible invariants; mutation tests reveal whether a suite detects wrong comparators, deleted exceptions, stale sources and false defaults; differential tests need genuinely independent oracles; conformance tests connect source spans, implementation, explanations and tests. Expected outputs embed legal interpretations and therefore require legal review. Passing tests cannot prove legal correctness or completeness.
Enumeration test source
The nonexclusive income list supplies category, broad-rule and omission traps for source-conformance testing. Pinned source or measurement: “§61. Gross income defined (a) General definition Except as otherwise provided in this subtitle, gross income means all income from whatever source derived, including (but not limited to) the following items: (1) Compensation for services, including fees, commissions, fringe benefits, and similar items; (2) Gross income derived from business; (3) Gains derived from dealings in property; (4) Interest; (5) Rents; (6) Royalties; (7) Dividends; (8) Annuities; (9) Income from life insurance and endowment contracts; (10) Pensions; (11) Income from discharge of indebtedness; (12) Distributive share of partnership gross income; (13) Income in respect of a decedent; and (14) Income from an interest in an estate or trust. (b) Cross references For items specifically included in gross income, see part II (sec. 71 and following). For items specifically excluded from gross income, see part III (sec. 101 and following). (Aug. 16, 1954, ch. 736, 68A Stat. 17 ; Pub. L. 98–369, div. A, title V, §531(c), July 18, 1984, 98 Stat. 884 ; Pub. L. 115–97, title I, §11051(b)(1)(A), Dec. 22, 2017, 131 Stat. 2089 .)” Coordinate: 26 U.S.C. § 61; https://www.neochart.com/catalog/federal/tax/title_26/chapter_1/section_61/title26_sec61_bcd7ff77d1ff/61_gross_income_defined_0001/index.html; data via neochart.com, snapshot 2026-08.
Enumerated-standard test source
The review standards, whole-record and prejudicial-error text supply completeness, mutation and explanation tests. Pinned source or measurement: “§706. Scope of review To the extent necessary to decision and when presented, the reviewing court shall decide all relevant questions of law, interpret constitutional and statutory provisions, and determine the meaning or applicability of the terms of an agency action. The reviewing court shall- (1) compel agency action unlawfully withheld or unreasonably delayed; and (2) hold unlawful and set aside agency action, findings, and conclusions found to be- (A) arbitrary, capricious, an abuse of discretion, or otherwise not in accordance with law; (B) contrary to constitutional right, power, privilege, or immunity; (C) in excess of statutory jurisdiction, authority, or limitations, or short of statutory right; (D) without observance of procedure required by law; (E) unsupported by substantial evidence in a case subject to sections 556 and 557 of this title or otherwise reviewed on the record of an agency hearing provided by statute; or (F) unwarranted by the facts to the extent that the facts are subject to trial de novo by the reviewing court. In making the foregoing determinations, the court shall review the whole record or those parts of it cited by a party, and due account shall be taken of the rule of prejudicial error. ( Pub. L. 89–554, Sept. 6, 1966, 80 Stat. 393 .)” Coordinate: 5 U.S.C. § 706; https://www.neochart.com/catalog/federal/title_5/section_706/title5_sec706_9a580d7b5bc7/706_scope_of_review_to_the_extent_necessary_to_decision_and_0001/index.html; data via neochart.com, snapshot 2026-08.
Pin the synthetic computational record
A synthetic conformance suite records rule and source versions, example and boundary inputs, expected outputs and reasons, generated domains, invariants, transformations, five semantic mutants, killed and surviving mutants, differential implementation, historical snapshots, source coverage, explanation checks, seeds, environment and legal and technical reviewers.
Work the audited application
Tests at ages just below, at and above the threshold kill the changed-comparator mutant. Income boundaries kill the reversed inequality. The deleted-exception and unknown-as-false mutants require dedicated cases. A source-citation assertion kills the provenance mutant. One unsupported monotonicity property is rejected because an exception can activate at higher income. Surviving mutants trigger suite improvement rather than a quality score.
Read the populated computational artifact
The testing record contains source version, rule version, test id, unit test, example, boundary, generated input, domain, property, assumption, metamorphic transform, invariant, mutant, mutation operator, killed, survived, differential oracle, regression, conformance span, source coverage, rule coverage, explanation assertion, seed, clock, parameter version, environment, failure, triage, legal reviewer, technical reviewer, and limitation. The artifact contains 16 populated rows.
Jurisdiction: US; as of 2026-08-28; not legal advice; Render structure, refuse interpretation, cite, abstain, and hand off.
RENDER STRUCTURE · REFUSE INTERPRETATION · CITE · ABSTAIN · HAND-OFF: render structure, refuse interpretation, cite provenance, abstain when unsupported, and hand off to human review.
Read the complete record
The complete record keeps sources, stated facts, and questions for review separate. Pinned sources and measurements: Verbatim text or bounded snapshot data. 26 U.S.C. § 61: Enumeration test source: The nonexclusive income list supplies category, broad-rule and omission traps for source-conformance testing.. 5 U.S.C. § 706: Enumerated-standard test source: The review standards, whole-record and prejudicial-error text supply completeness, mutation and explanation tests.. Synthetic computational record: Classroom inputs and intermediate states. Implementation: Eligibility function has resident, age, income and exception predicates with source mapping. Mutants: Change greater-than-or-equal to greater-than, reverse income comparator, delete exception, treat unknown as false and remove source citation. Suite: Examples, thresholds, generated properties, metamorphic changes, historical regression, source conformance, explanation assertions and independent oracle. Audit trace: Semantics, provenance, execution, evidence, limits and handoff. Unit and example: One rule node or function, stated inputs, expected output, expected reason and source coordinate. Boundary: Just below, at and above thresholds; date boundaries; zero, negative, maximum, empty, missing, disputed and not-applicable values. Property and metamorphic: Invariant over generated inputs and controlled transformations, with legal assumptions stated rather than invented monotonicity. Mutation: Deliberately alter comparator, threshold, condition, exception, priority, period, rounding, source or explanation and require tests to fail. Differential: Compare independent implementations or previous version only where semantics and source package are identical. Conformance: Map every source span to tests and every rule node to source; detect omissions, additions, dead rules, unreachable exceptions and orphan tests. Nondeterminism and review: Freeze clocks and parameters, seed generation, record solver or model version, inspect failures and require legal review of expected values.
Narrow summary
Test boundaries, invariants, mutations, source conformance and explanations, review expected semantics legally, and never claim passing tests prove the code is law.