Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/aien-protocols-mv/blob/main/crates/aien-pi-spark-task/tests/vectors.rs # aien-protocols-mv Canonical specifications, wire protocols, and schemas for the AIEN sovereign ecosystem Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers branch `main` Branches Tags History `aien-protocols-mv / crates / aien-pi-spark-task / tests / vectors.rs` 58 lines ยท 2001 bytes Raw Blame History 1 //! Walks `specs/pi-spark-task/vectors/expected.txt` and requires the Rust 2 //! reader to print the same verdict line as the C reference checker 3 //! (`tools/pst_verify.c`) for every file, and to write every accepted message 4 //! back out as the identical bytes. 5 6 use std::path::PathBuf; 7 8 use aien_pi_spark_task::{decode, encode, verdict_line, MAX_MESSAGE}; 9 10 fn vectors_dir() -> PathBuf { 11 PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("../../specs/pi-spark-task/vectors") 12 } 13 14 #[test] 15 fn every_expected_line_matches_the_c_checker() { 16 let dir = vectors_dir(); 17 let list = std::fs::read_to_string(dir.join("expected.txt")).expect("read expected.txt"); 18 let mut checked = 0usize; 19 let mut accepted = 0usize; 20 let mut failures = Vec::new(); 21 for line in list.lines() { 22 if line.is_empty() || line.starts_with('#') { 23 continue; 24 } 25 let (name, want) = line 26 .split_once(' ') 27 .expect("line has a file name and a verdict"); 28 let bytes = std::fs::read(dir.join(name)).expect("read vector"); 29 let result = decode(&bytes); 30 let got = verdict_line(&result); 31 if got != want { 32 failures.push(format!("{name}\n expected: {want}\n got: {got}")); 33 } 34 if let Ok(msg) = &result { 35 let mut out = [0u8; MAX_MESSAGE]; 36 let n = encode(&msg.header, msg.payload, &mut out).expect("re-encode accepted message"); 37 if out[..n] != bytes[..] { 38 failures.push(format!("{name}: round trip gave different bytes")); 39 } 40 accepted += 1; 41 } 42 checked += 1; 43 } 44 assert!( 45 failures.is_empty(), 46 "{} of {checked} vectors differ:\n{}", 47 failures.len(), 48 failures.join("\n") 49 ); 50 assert!( 51 checked >= 23, 52 "expected at least 23 vectors, found {checked}" 53 ); 54 assert!( 55 accepted >= 4, 56 "expected at least 4 accepted vectors, found {accepted}" 57 ); 58 }