1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//! v2.54.0 — the measured-accuracy instrument for the IDP-E recognizer.
//!
//! This is the honest realization of the design decision: **we measure, we do not claim.**
//! The test recognises a set of synthetic clean-machine-print glyphs (the v1
//! scope, the design decision) and computes character accuracy — a real number on a real
//! fixture set. It asserts a floor that proves the engine *works on its declared
//! scope*, and it PRINTS the accuracy so a human sees the measurement.
//!
//! It is deliberately NOT a market comparison: no tesseract, no Textract, no
//! "beats X". Those belong on the Sandbox against named baselines
//! ([[project-benchmarks-on-sandbox]]); this harness is the local instrument that
//! will feed it. The number here is the reference-set accuracy under a pinned
//! engine, nothing more.
use axon::idpe::{recognise, RasterTile};
/// Render an ASCII-art glyph (`#` = ink) into a grayscale [`RasterTile`] with a
/// 1px white margin (so components do not touch the border).
fn glyph(rows: &[&str]) -> RasterTile {
let ih = rows.len();
let iw = rows.iter().map(|r| r.len()).max().unwrap();
let (w, h) = (iw + 2, ih + 2);
let mut gray = vec![255u8; w * h];
for (y, r) in rows.iter().enumerate() {
for x in 0..iw {
if r.as_bytes().get(x).copied().unwrap_or(b' ') == b'#' {
gray[(y + 1) * w + (x + 1)] = 0;
}
}
}
RasterTile { width: w, height: h, gray }
}
/// The reference fixture set — clean machine-print glyphs the v1 prototype set
/// covers, each with its expected character.
fn fixtures() -> Vec<(char, RasterTile)> {
vec![
(
'0',
glyph(&[" ### ", "# #", "# #", "# #", "# #", "# #", " ### "]),
),
('1', glyph(&[" # ", " # ", " # ", " # ", " # ", " # ", " # "])),
(
'8',
glyph(&[" ### ", "# #", "# #", " ### ", "# #", "# #", " ### "]),
),
(
'H',
glyph(&["# #", "# #", "# #", "#####", "# #", "# #", "# #"]),
),
('-', glyph(&[" ", " ", " ", "#####", " ", " ", " "])),
('.', glyph(&[" ", " ", " ", " ", " ", " ## ", " ## "])),
]
}
#[test]
fn idpe_recognizes_the_reference_set_and_reports_accuracy() {
let fx = fixtures();
let total = fx.len();
let mut correct = 0;
let mut confidence_sum = 0.0;
let mut report = String::new();
for (expected, tile) in &fx {
let page = recognise(tile);
let got = page.tree.text.chars().next().unwrap_or('\u{FFFD}');
let conf = page.spans.first().map(|s| s.confidence).unwrap_or(0.0);
confidence_sum += conf;
let ok = got == *expected;
if ok {
correct += 1;
}
report.push_str(&format!(
" '{expected}' → '{got}' (conf {conf:.3}) {}\n",
if ok { "OK" } else { "MISS" }
));
}
let accuracy = correct as f64 / total as f64;
let mean_conf = confidence_sum / total as f64;
// Print the measurement (visible with `--nocapture`) — the honest instrument.
println!(
"v2.54.0 IDP-E reference-set accuracy: {correct}/{total} = {:.1}% | mean confidence {:.3}\n{report}",
accuracy * 100.0,
mean_conf
);
// Floor: the engine must read its OWN declared scope essentially perfectly.
// This proves it works — it is NOT a claim about arbitrary documents.
assert!(
accuracy >= 0.83,
"reference-set accuracy {accuracy:.3} below floor — the engine regressed on its own scope"
);
}
#[test]
fn correct_reads_clear_the_default_confidence_floor() {
// A correctly-read clean glyph should clear a reasonable anchor floor (0.5),
// so it is believed; the epistemic contract only bites on genuine ambiguity.
let fx = fixtures();
for (expected, tile) in &fx {
let page = recognise(tile);
let got = page.tree.text.chars().next().unwrap_or('\u{FFFD}');
if got == *expected {
let conf = page.spans[0].confidence;
assert!(conf > 0.0, "a correct read of '{expected}' has zero confidence");
}
}
}