mirror of
https://codeberg.org/unspeaker/tengri.git
synced 2025-12-06 19:56:44 +01:00
This commit is contained in:
parent
9fb5d2d9f7
commit
2b208e3c49
11 changed files with 219 additions and 198 deletions
|
|
@ -19,6 +19,8 @@ pub type Usually<T> = Result<T, Box<dyn Error>>;
|
|||
/// Standard optional result type.
|
||||
pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
|
||||
|
||||
#[cfg(test)] use proptest_derive::Arbitrary;
|
||||
|
||||
#[cfg(test)] #[test] fn test_stub_output () -> Usually<()> {
|
||||
use crate::*;
|
||||
struct TestOutput([u16;4]);
|
||||
|
|
@ -43,3 +45,152 @@ pub type Perhaps<T> = Result<Option<T>, Box<dyn Error>>;
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_space () {
|
||||
use crate::*;
|
||||
assert_eq!(Area::center(&[10u16, 10, 20, 20]), [20, 20]);
|
||||
}
|
||||
|
||||
#[cfg(test)] #[test] fn test_iter_map () {
|
||||
struct Foo;
|
||||
impl<T: Output> Content<T> for Foo {}
|
||||
fn make_map <T: Output, U: Content<T> + Send + Sync> (data: &Vec<U>) -> impl Content<T> {
|
||||
Map::new(||data.iter(), |foo, index|{})
|
||||
}
|
||||
let data = vec![Foo, Foo, Foo];
|
||||
//let map = make_map(&data);
|
||||
}
|
||||
|
||||
#[cfg(test)] mod test {
|
||||
use crate::*;
|
||||
use proptest::{prelude::*, option::of};
|
||||
use proptest::option::of;
|
||||
|
||||
proptest! {
|
||||
#[test] fn proptest_direction (
|
||||
d in prop_oneof![
|
||||
Just(North), Just(South),
|
||||
Just(East), Just(West),
|
||||
Just(Above), Just(Below)
|
||||
],
|
||||
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,
|
||||
) {
|
||||
let _ = d.split_fixed([x, y, w, h], a);
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test] fn proptest_size (
|
||||
x in u16::MIN..u16::MAX,
|
||||
y in u16::MIN..u16::MAX,
|
||||
a in u16::MIN..u16::MAX,
|
||||
b in u16::MIN..u16::MAX,
|
||||
) {
|
||||
let size = [x, y];
|
||||
let _ = size.w();
|
||||
let _ = size.h();
|
||||
let _ = size.wh();
|
||||
let _ = size.clip_w(a);
|
||||
let _ = size.clip_h(b);
|
||||
let _ = size.expect_min(a, b);
|
||||
let _ = size.to_area_pos();
|
||||
let _ = size.to_area_size();
|
||||
}
|
||||
}
|
||||
|
||||
proptest! {
|
||||
#[test] fn proptest_area (
|
||||
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,
|
||||
b in u16::MIN..u16::MAX,
|
||||
) {
|
||||
let _: [u16;4] = <[u16;4] as Area<u16>>::zero();
|
||||
let _: [u16;4] = <[u16;4] as Area<u16>>::from_position([a, b]);
|
||||
let _: [u16;4] = <[u16;4] as Area<u16>>::from_size([a, b]);
|
||||
let area: [u16;4] = [x, y, w, h];
|
||||
let _ = area.expect_min(a, b);
|
||||
let _ = area.xy();
|
||||
let _ = area.wh();
|
||||
let _ = area.xywh();
|
||||
let _ = area.clip_h(a);
|
||||
let _ = area.clip_w(b);
|
||||
let _ = area.clip([a, b]);
|
||||
let _ = area.set_w(a);
|
||||
let _ = area.set_h(b);
|
||||
let _ = area.x2();
|
||||
let _ = area.y2();
|
||||
let _ = area.lrtb();
|
||||
let _ = area.center();
|
||||
let _ = area.center_x(a);
|
||||
let _ = area.center_y(b);
|
||||
let _ = area.center_xy([a, b]);
|
||||
let _ = area.centered();
|
||||
}
|
||||
}
|
||||
|
||||
macro_rules! test_op_transform {
|
||||
($fn:ident, $Op:ident) => {
|
||||
proptest! {
|
||||
#[test] fn $fn (
|
||||
op_x in of(u16::MIN..u16::MAX),
|
||||
op_y in of(u16::MIN..u16::MAX),
|
||||
content in "\\PC*",
|
||||
x in u16::MIN..u16::MAX,
|
||||
y in u16::MIN..u16::MAX,
|
||||
w in u16::MIN..u16::MAX,
|
||||
h in u16::MIN..u16::MAX,
|
||||
) {
|
||||
if let Some(op) = match (op_x, op_y) {
|
||||
(Some(x), Some(y)) => Some($Op::xy(x, y, content)),
|
||||
(Some(x), None) => Some($Op::x(x, content)),
|
||||
(Some(y), None) => Some($Op::y(y, content)),
|
||||
_ => None
|
||||
} {
|
||||
assert_eq!(Content::layout(&op, [x, y, w, h]),
|
||||
Render::layout(&op, [x, y, w, h]));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
test_op_transform!(proptest_op_fixed, Fixed);
|
||||
test_op_transform!(proptest_op_min, Min);
|
||||
test_op_transform!(proptest_op_max, Max);
|
||||
test_op_transform!(proptest_op_push, Push);
|
||||
test_op_transform!(proptest_op_pull, Pull);
|
||||
test_op_transform!(proptest_op_shrink, Shrink);
|
||||
test_op_transform!(proptest_op_expand, Expand);
|
||||
test_op_transform!(proptest_op_margin, Margin);
|
||||
test_op_transform!(proptest_op_padding, Padding);
|
||||
|
||||
proptest! {
|
||||
#[test] fn proptest_op_bsp (
|
||||
d in prop_oneof![
|
||||
Just(North), Just(South),
|
||||
Just(East), Just(West),
|
||||
Just(Above), Just(Below)
|
||||
],
|
||||
a in "\\PC*",
|
||||
b in "\\PC*",
|
||||
x in u16::MIN..u16::MAX,
|
||||
y in u16::MIN..u16::MAX,
|
||||
w in u16::MIN..u16::MAX,
|
||||
h in u16::MIN..u16::MAX,
|
||||
) {
|
||||
let bsp = Bsp(d, a, b);
|
||||
assert_eq!(
|
||||
Content::layout(&bsp, [x, y, w, h]),
|
||||
Render::layout(&bsp, [x, y, w, h]),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue