//! Integer neural fields (extensions/neural-fields.md): the corpus volumetric-conformance/fields/ //! regenerates byte for byte from its scenes and holds nothing else; every value, render, //! refusal, level application and layer outcome it states is reproduced, for every prefix of //! each scene's levels; every fault §11 plants in the decode is caught; and §8's table lists //! exactly the codes the corpus's refusals and level applications carry. #![cfg(feature = "field_int")] use std::collections::BTreeSet; use std::path::PathBuf; use wai::int_field::{corpus, Plant}; fn wai_dir() -> PathBuf { PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("..") } fn corpus_dir() -> PathBuf { wai_dir().join("volumetric-conformance/fields") } #[test] fn the_corpus_regenerates_and_holds_nothing_else() { let bad = corpus::check(&corpus_dir()).expect("the corpus builds"); assert!(bad.is_empty(), "{bad:?}"); } #[test] fn every_value_render_and_refusal_is_reproduced() { let v = corpus::verify(&corpus_dir(), Plant::None).expect("the corpus reads"); assert!(v.fails.is_empty(), "{:?}", v.fails); assert!(v.values > 0 && v.renders > 0 && v.refusals > 0 && v.applications > 0 && v.offers > 0, "{v:?}"); } #[test] fn every_planted_fault_is_caught() { for plant in Plant::ALL { let v = corpus::verify(&corpus_dir(), plant).expect("the corpus reads"); assert!(!v.fails.is_empty(), "the planted fault {} is not caught", plant.name()); } } #[test] fn the_refusal_table_is_the_corpus_codes() { let text = std::fs::read_to_string(wai_dir().join("extensions/neural-fields.md")).unwrap(); let start = text.find("## 8.").expect("§8"); let end = text[start..].find("\n## 9.").map(|i| start + i).unwrap(); let table: BTreeSet<&str> = text[start..end] .lines() .filter_map(|l| l.strip_prefix("| `")) .filter_map(|l| l.split('`').next()) .collect(); let v: serde_json::Value = serde_json::from_slice(&std::fs::read(corpus_dir().join("vectors.json")).unwrap()).unwrap(); let mut used: BTreeSet<&str> = v["refusals"].as_array().unwrap().iter().map(|r| r["code"].as_str().unwrap()).collect(); for g in v["geometry"].as_array().unwrap() { used.extend(g["expect"].as_array().unwrap().iter().map(|e| e.as_str().unwrap()).filter(|e| *e != "ok")); } assert_eq!(table, used); }