use super::{Dimensions, Rect};
const CODED: Dimensions = Dimensions::new(1920, 1080);
#[test]
fn a_rect_flush_with_an_edge_is_contained() {
let table = [
Rect::new(0, 0, 1920, 1080),
Rect::new(480, 0, 1440, 1080),
Rect::new(0, 80, 1920, 1000),
Rect::new(1919, 1079, 1, 1),
];
for r in table {
assert!(CODED.contains(&r), "{r:?} ends on an edge, not past one");
}
}
#[test]
fn one_pixel_past_an_edge_is_not_contained() {
let table = [
Rect::new(0, 0, 1921, 1080),
Rect::new(0, 0, 1920, 1081),
Rect::new(481, 0, 1440, 1080),
Rect::new(0, 81, 1920, 1000),
Rect::new(1920, 1079, 1, 1),
Rect::new(1919, 1080, 1, 1),
];
for r in table {
assert!(!CODED.contains(&r), "{r:?} reaches past an edge");
}
}
#[test]
fn an_empty_rect_is_contained_wherever_its_origin_is() {
for r in [
Rect::default(),
Rect::new(0, 0, 0, 1080),
Rect::new(0, 0, 1920, 0),
Rect::new(1920, 1080, 0, 0),
Rect::new(960, 540, 0, 0),
] {
assert!(CODED.contains(&r), "{r:?} is empty and inside");
}
for r in [Rect::new(1921, 0, 0, 0), Rect::new(0, 1081, 0, 0)] {
assert!(!CODED.contains(&r), "{r:?} is empty but originates outside");
}
assert!(Dimensions::default().contains(&Rect::default()));
assert!(!Dimensions::default().contains(&Rect::new(0, 0, 1, 1)));
}
#[test]
fn an_overflowing_extent_is_not_contained() {
let full = Dimensions::new(u32::MAX, u32::MAX);
for r in [
Rect::new(u32::MAX, 0, 1, 0),
Rect::new(0, u32::MAX, 0, 1),
Rect::new(u32::MAX, u32::MAX, u32::MAX, u32::MAX),
] {
assert!(!full.contains(&r), "{r:?} overflows its own extent");
}
assert!(full.contains(&Rect::new(0, 0, u32::MAX, u32::MAX)));
}
#[test]
fn the_predicate_is_usable_in_const_context() {
const ANSWERS: [bool; 2] = [
CODED.contains(&Rect::new(480, 0, 1440, 1080)),
CODED.contains(&Rect::new(481, 0, 1440, 1080)),
];
assert_eq!(ANSWERS, [true, false]);
}