use aion_verify::{for_all, for_all_in, for_all_pairs, for_all_u8, for_all_where};
#[test]
fn audit_case_count_is_exactly_the_domain_size() {
let bounds: Vec<u64> = (0..=48).collect();
let v = for_all_pairs(&bounds, &bounds, |&lo, &hi| {
if lo > hi {
return true; }
for_all_in(lo, hi, |_| true).cases() == hi - lo + 1
});
assert!(
v.is_proven(),
"case count wrong at {:?}",
v.counterexample()
);
}
#[test]
fn audit_reports_the_first_counterexample_with_exact_prior_count() {
let v = for_all_u8(|t| {
let r = for_all_u8(|x| x != t);
r.counterexample() == Some(&t) && r.cases() == t as u64 && !r.is_proven()
});
assert!(
v.is_proven(),
"first-counterexample property fails at {:?}",
v.counterexample()
);
}
#[test]
fn audit_empty_domain_is_vacuously_proven() {
let empty = for_all_in(5, 3, |_| false);
assert!(empty.is_proven());
assert_eq!(empty.cases(), 0);
assert_eq!(empty.counterexample(), None);
let none: [u8; 0] = [];
assert!(for_all(none, |_| false).is_proven());
assert!(for_all_where(0u8..=255, |_| false, |_| false).is_proven());
assert_eq!(for_all_where(0u8..=255, |_| false, |_| false).cases(), 0);
}
#[test]
fn audit_u64_max_boundary_does_not_overflow_or_panic() {
assert_eq!(for_all_in(u64::MAX, u64::MAX, |_| true).cases(), 1);
let near_top = for_all_in(u64::MAX - 3, u64::MAX, |x| x >= u64::MAX - 3);
assert!(near_top.is_proven());
assert_eq!(near_top.cases(), 4);
let r = for_all_in(u64::MAX - 3, u64::MAX, |x| x != u64::MAX);
assert_eq!(r.counterexample(), Some(&u64::MAX));
}
#[test]
fn audit_precondition_counts_only_admitted_inputs() {
assert_eq!(
for_all_where(0u16..=255, |x| x % 2 == 0, |_| true).cases(),
128
);
assert_eq!(for_all_where(0u16..=99, |_| true, |_| true).cases(), 100);
}
#[test]
fn audit_pairs_cover_the_full_cartesian_product() {
let a = [1u32, 2, 3, 4];
let b = [9u32, 8];
assert_eq!(for_all_pairs(&a, &b, |_, _| true).cases(), 8);
let bad = for_all_pairs(&a, &b, |&x, &y| !(x == 2 && y == 9));
assert_eq!(bad.counterexample(), Some(&(2u32, 9u32)));
}
#[test]
fn audit_a_true_property_over_u8_is_a_full_proof() {
let v = for_all_u8(|x| x.wrapping_add(1) != x);
assert!(v.is_proven());
assert_eq!(v.cases(), 256);
}