use proptest::prelude::*;
use tenuo::constraints::*;
#[test]
fn test_alloy_all_and_any_conformance() {
let parent_any = Any::new(vec![
Constraint::Exact(Exact::new("req1")),
Constraint::Exact(Exact::new("req2")),
]);
let child_any_valid = Any::new(vec![Constraint::Exact(Exact::new("req1"))]);
assert!(
Constraint::Any(parent_any.clone())
.validate_attenuation(&Constraint::Any(child_any_valid))
.is_err() );
let parent_all = All::new(vec![Constraint::Exact(Exact::new("A"))]);
let child_all_valid = All::new(vec![
Constraint::Exact(Exact::new("A")),
Constraint::Exact(Exact::new("B")),
]);
assert!(Constraint::All(parent_all)
.validate_attenuation(&Constraint::All(child_all_valid))
.is_ok());
}
proptest! {
#[test]
fn oracle_range_subsumes_exact_tight_bounds(
min in 0i64..1000,
max in 1001i64..2000,
val in 0i64..3000
) {
let parent = Constraint::Range(Range::new(Some(min as f64), Some(max as f64)).unwrap());
let child = Constraint::Exact(Exact::new(val));
let attenuation_result = parent.validate_attenuation(&child);
if val >= min && val <= max {
prop_assert!(attenuation_result.is_ok(), "Valid bounds mathematically must be OK in Rust");
} else {
prop_assert!(attenuation_result.is_err(), "Topological bounds exceeded mathematically must throw Err");
}
}
#[test]
fn oracle_cidr_network_algebra(
ip1 in 0u8..255, ip2 in 0u8..255, ip3 in 0u8..255, _ip4 in 0u8..255,
prefix_len in 0u8..24
) {
let parent_ip = format!("{}.{}.{}.0/{}", ip1, ip2, ip3, prefix_len);
let child_ip = format!("{}.{}.{}.128/{}", ip1, ip2, ip3, prefix_len + 1);
if let (Ok(parent), Ok(child)) = (Cidr::new(&parent_ip), Cidr::new(&child_ip)) {
prop_assert!(Constraint::Cidr(parent).validate_attenuation(&Constraint::Cidr(child)).is_ok());
}
}
}