Add CCLite 0.2.8 verification cases
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import math
|
||||
from pathlib import Path
|
||||
|
||||
from common_csv import add_failure, as_float, as_int, read_required_csv, write_verification_report
|
||||
|
||||
|
||||
GEOMETRY_HEADERS = [
|
||||
"metric",
|
||||
"expected",
|
||||
"actual",
|
||||
"tolerance",
|
||||
"degenerate_count",
|
||||
"nonfinite_count",
|
||||
]
|
||||
|
||||
|
||||
def build_report(args: argparse.Namespace) -> dict:
|
||||
input_path = Path(args.input)
|
||||
failed: list[str] = []
|
||||
metrics: dict[str, int | float] = {}
|
||||
|
||||
try:
|
||||
_, rows = read_required_csv(input_path, GEOMETRY_HEADERS)
|
||||
except AssertionError as exc:
|
||||
rows = []
|
||||
failed.append(str(exc))
|
||||
|
||||
degenerate_total = 0
|
||||
nonfinite_total = 0
|
||||
checked_rows = 0
|
||||
for index, row in enumerate(rows, start=1):
|
||||
location = f"{input_path.name} row {index}"
|
||||
metric = row.get("metric", "")
|
||||
try:
|
||||
expected = as_float(row, "expected")
|
||||
actual = as_float(row, "actual")
|
||||
tolerance = as_float(row, "tolerance")
|
||||
degenerate_count = as_int(row, "degenerate_count")
|
||||
nonfinite_count = as_int(row, "nonfinite_count")
|
||||
except AssertionError as exc:
|
||||
failed.append(f"{location}: {exc}")
|
||||
continue
|
||||
|
||||
checked_rows += 1
|
||||
degenerate_total += degenerate_count
|
||||
nonfinite_total += nonfinite_count
|
||||
if not math.isfinite(actual):
|
||||
add_failure(failed, location, metric, "finite value", actual)
|
||||
if abs(actual - expected) > tolerance:
|
||||
add_failure(failed, location, metric, f"{expected} +/- {tolerance}", actual)
|
||||
if nonfinite_count != 0:
|
||||
add_failure(failed, location, "nonfinite_count", 0, nonfinite_count)
|
||||
|
||||
if checked_rows == 0:
|
||||
failed.append("geometry primitive report has no data rows")
|
||||
if degenerate_total < args.min_degenerate_count:
|
||||
add_failure(failed, input_path.name, "degenerate_count", f">={args.min_degenerate_count}", degenerate_total)
|
||||
if nonfinite_total != 0:
|
||||
add_failure(failed, input_path.name, "nonfinite_total", 0, nonfinite_total)
|
||||
|
||||
metrics["checked_rows"] = checked_rows
|
||||
metrics["degenerate_count"] = degenerate_total
|
||||
metrics["nonfinite_count"] = nonfinite_total
|
||||
return {
|
||||
"case_id": args.case_id,
|
||||
"status": "PASS" if not failed else "FAIL",
|
||||
"metrics": metrics,
|
||||
"failed_checks": failed,
|
||||
"input": str(input_path),
|
||||
"output_files": {
|
||||
"geometry_report": str(input_path),
|
||||
},
|
||||
}
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("--case-id", required=True)
|
||||
parser.add_argument("--input", required=True)
|
||||
parser.add_argument("--report", required=True)
|
||||
parser.add_argument("--min-degenerate-count", type=int, default=2)
|
||||
args = parser.parse_args()
|
||||
|
||||
report = build_report(args)
|
||||
report_path = Path(args.report)
|
||||
write_verification_report(report_path, report)
|
||||
print(f"{report['case_id']} {report['status']} -> {report_path}")
|
||||
return 0 if report["status"] == "PASS" else 1
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
raise SystemExit(main())
|
||||
Reference in New Issue
Block a user