use proptest::prelude::*;
use rust_widgets::core::{Color, Point, Rect};
proptest! {
#[test]
fn color_rgba_roundtrip(r in 0u8.., g in 0u8.., b in 0u8.., a in 0u8..) {
let c = Color::rgba(r, g, b, a);
assert_eq!(c.r, r);
assert_eq!(c.g, g);
assert_eq!(c.b, b);
assert_eq!(c.a, a);
}
#[test]
fn rect_contains_center(w: u32, h: u32) {
let w = w % 1000 + 1;
let h = h % 1000 + 1;
let r = Rect::new(0, 0, w, h);
assert!(r.contains(Point::new((w / 2) as i32, (h / 2) as i32)));
assert!(r.contains(Point::new(0, 0)));
assert!(!r.contains(Point::new(w as i32, 0)));
assert!(!r.contains(Point::new(0, h as i32)));
}
#[test]
fn rect_intersection_commutative(x in 0i32..1000i32, y in 0i32..1000i32, w in 1u32..500u32, h in 1u32..500u32) {
let a = Rect::new(x, y, w, h);
let b = Rect::new(x + (w as i32 / 2), y + (h as i32 / 2), w, h);
let ab = a.intersection(&b);
let ba = b.intersection(&a);
assert_eq!(ab, ba, "intersection must be commutative");
}
#[test]
fn color_premultiplied_invariants(r in 0u8.., g in 0u8.., b in 0u8.., a in 0u8..) {
let c = Color::rgba(r, g, b, a);
let _ = c; }
}