add more proptests for output

This commit is contained in:
🪞👃🪞 2025-01-27 18:41:27 +01:00
parent c78dd2453a
commit 2e18ca96fd
9 changed files with 154 additions and 78 deletions

33
output/src/direction.rs Normal file
View file

@ -0,0 +1,33 @@
use crate::*;
/// A cardinal direction.
#[derive(Copy, Clone, PartialEq)]
pub enum Direction { North, South, East, West, Above, Below }
impl Direction {
pub fn split_fixed <N: Coordinate> (self, area: impl Area<N>, a: N) -> ([N;4],[N;4]) {
let [x, y, w, h] = area.xywh();
match self {
North => ([x, y.plus(h).minus(a), w, a], [x, y, w, h.minus(a)]),
South => ([x, y, w, a], [x, y.plus(a), w, h.minus(a)]),
East => ([x, y, a, h], [x.plus(a), y, w.minus(a), h]),
West => ([x.plus(w).minus(a), y, a, h], [x, y, w.minus(a), h]),
Above | Below => (area.xywh(), area.xywh())
}
}
}
#[cfg(test)] mod test_op_transform {
use super::*;
use proptest::prelude::*;
proptest! {
#[test] fn test_direction (
x in u16::MIN..u16::MAX,
y in u16::MIN..u16::MAX,
w in u16::MIN..u16::MAX,
h in u16::MIN..u16::MAX,
a in u16::MIN..u16::MAX,
) {
for d in [North, South, East, West, Above, Below].iter() {
let _ = d.split_fixed([x, y, w, h], a);
}
}
}
}