use verif::smt::{self, var, Verdict};
#[allow(dead_code)]
#[path = "../examples/flight_control.rs"]
mod flight_control;
#[test]
fn the_vacuity_guard_accepts_a_width_that_can_hold_the_bound() {
smt::with_fresh(|| {
assert!(
flight_control::the_bound_is_refutable_at(22),
"22 bits can represent 4 095 000, so the guard must accept the width; a guard \
over the clamped product cannot, because the clamp caps it at the bound"
);
});
}
#[test]
fn the_vacuity_guard_rejects_a_width_that_cannot_hold_the_bound() {
smt::with_fresh(|| {
assert!(
!flight_control::the_bound_is_refutable_at(16),
"16 bits cannot represent 4 095 000, so the guard must reject the width"
);
});
}
#[test]
fn a_clamped_product_is_never_above_the_bound_at_any_width() {
for width in [16u8, 22] {
smt::with_fresh(|| {
let raw = var(width);
let max = smt::word(4095, width);
let clamped = smt::ite(raw.gt(max), max, raw);
let scaled = clamped * 1000u32;
assert_eq!(
smt::find_model(scaled.gt_val(4_095_000)),
Verdict::Unsat,
"at {width} bits the clamped product must never exceed the bound, which is \
exactly why a guard over it asserted nothing"
);
});
}
}