rust_widgets 0.9.6

Pure Rust cross-platform native GUI library with hardware-adaptive rendering, 60+ widgets, touch/gesture support, i18n, and SVG-pipeline-accurate output
//! Property-based tests using proptest (BLUE11 R3.8).
//!
//! These tests use random input to verify widget invariants hold
//! across a wide range of inputs.
//!
//! Run with: cargo test --test property_based_tests

use proptest::prelude::*;
use rust_widgets::core::{Color, Point, Rect};

// ── Arbitrary implementations for core types ──

proptest! {
    /// Color RGBA components are always in u8 range (guaranteed by type).
    /// Roundtrip property: creating a Color from components then reading
    /// them back yields the original values.
    #[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);
    }

    /// For any Rect, its center point is always contained.
    #[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)));
        // Origin is always contained
        assert!(r.contains(Point::new(0, 0)));
        // Points outside width/height should NOT be contained
        assert!(!r.contains(Point::new(w as i32, 0)));
        assert!(!r.contains(Point::new(0, h as i32)));
    }

    /// Rect intersection is always commutative.
    #[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");
    }

    /// For any Color, premultiplied alpha with itself should produce the same color.
    #[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; // Structure: invariant is that type construction never panics
    }
}