#!/usr/bin/env bash # prove.sh — evidence the plot instrument works. Both directions. set -uo pipefail D="$(cd "$(dirname "$0")" && pwd)" python3 - "$D" <<'PY' import sys, csv, os D = sys.argv[1]; sys.path.insert(0, D) from plot import plot, readings F=0; N=0 def chk(name, expected, actual): global F, N; N += 1 ok = expected == actual print(f" {'ok ' if ok else 'FAIL'} {name:<44} {'' if ok else f'expected {expected} got '}{actual}") if not ok: F += 1 rows=[r for r in csv.reader(open(f"{D}/reference/KNOWN-SERIES.tsv"), delimiter="\t") if r and not r[0].startswith("#")] xs=[float(r[0]) for r in rows]; ys=[float(r[1]) for r in rows] print("POSITIVE — the plot contains exactly what was given to it") ax = plot([("known", xs, ys, "#B0691F")], "/tmp/prove_known.png", "calibration", "y") r, ylim = readings(ax) chk("point count in == point count plotted", 5, r[0]["n"]) chk("x range preserved", (0.0, 4.0), (r[0]["xmin"], r[0]["xmax"])) chk("y range preserved", (5.0, 40.0), (r[0]["ymin"], r[0]["ymax"])) chk("final point not dropped/sorted", (4.0, 5.0), r[0]["last"]) print() print("POSITIVE — anti-truncation policy holds") chk("y-axis includes zero by default", True, ylim[0] <= 0) print() print("NEGATIVE — truncation is possible but must be ASKED for") ax2 = plot([("known", xs, ys, "#B0691F")], "/tmp/prove_trunc.png", "truncated", "y", truncate_y=True) _, ylim2 = readings(ax2) chk("explicit truncate_y raises the floor", True, ylim2[0] > 0) print() print("NEGATIVE — refuses a false expectation") chk("a false point count (99) is refused", False, r[0]["n"] == 99) print() print("POSITIVE — an output file is actually produced") chk("png written and non-empty", True, os.path.getsize("/tmp/prove_known.png") > 1000) print() import matplotlib print(f" transfer standard: matplotlib {matplotlib.__version__}") print(f" {'PROVEN' if F==0 else 'NOT PROVEN'} — {N} checks, {F} failed") sys.exit(F) PY