use verif::prelude::*;
#[test]
fn readme_flagship_example_proves_a_bound() {
let proved = verif::smt::with_fresh(|| {
let x = var(8);
(x & 0x0fu32).lt_val(16).prove().is_proved()
});
assert!(proved);
}
#[test]
fn readme_install_uses_the_published_crate() {
let readme = include_str!("../README.md");
let install = readme
.split("## Installation")
.nth(1)
.expect("README must have an Installation section")
.split("\n## ")
.next()
.expect("the Installation section must end at the next heading");
assert!(
install.contains("verif = \"0.2\""),
"Installation must depend on the published `verif = \"0.2\"`; got:\n{install}"
);
assert!(
!install.contains("git = \"https://github.com/cipansor/verif\""),
"Installation must not fall back to a git dependency once the crate is published"
);
assert!(
install.contains("https://crates.io/crates/verif-arithmetic"),
"Installation must name the published `verif-arithmetic` sibling"
);
}
#[test]
fn readme_two_ways_on_target_snippet_proves_and_computes() {
use verif::prelude::*;
fn clamp100(n: u32) -> u32 {
let ok = verif::smt::with_fresh(|| {
let x = var(32);
let clamped = verif::smt::ite(x.gt_val(100), verif::smt::word(100, 32), x);
clamped.le_val(100).prove().is_proved()
});
assert!(ok, "clamp100's bound did not discharge");
if n > 100 { 100 } else { n }
}
assert_eq!(clamp100(0), 0);
assert_eq!(clamp100(100), 100);
assert_eq!(clamp100(101), 100);
assert_eq!(clamp100(u32::MAX), 100);
let refuted = verif::smt::with_fresh(|| {
let x = var(32);
verif::smt::ite(x.gt_val(100), verif::smt::word(100, 32), x)
.lt_val(50)
.prove()
});
assert!(!refuted.is_proved(), "a false bound must not be proved");
}