Structured test cases

This commit is contained in:
Clark Moody 2020-05-27 14:24:33 -05:00
parent 9079014974
commit 858eafe22e

View File

@ -59,85 +59,156 @@ impl Axis {
mod tests { mod tests {
use super::*; use super::*;
#[test] enum Case {
fn split_horizontal() { Horizontal {
let a = Axis::Horizontal; overall_height: f32,
// rectangle height, spacing, top height, bottom y, bottom height spacing: f32,
let cases = vec![ top_height: f32,
// Even height, even spacing bottom_y: f32,
(10.0, 2.0, 4.0, 6.0, 4.0), bottom_height: f32,
// Odd height, even spacing },
(9.0, 2.0, 4.0, 6.0, 3.0), Vertical {
// Even height, odd spacing overall_width: f32,
(10.0, 1.0, 5.0, 6.0, 4.0), spacing: f32,
// Odd height, odd spacing left_width: f32,
(9.0, 1.0, 4.0, 5.0, 4.0), right_x: f32,
]; right_width: f32,
for case in cases { },
let (h0, spacing, h1_top, y_bottom, h1_bottom) = case;
let r = Rectangle {
x: 0.0,
y: 0.0,
width: 10.0,
height: h0,
};
let (top, bottom) = a.split(&r, 0.5, spacing);
assert_eq!(
top,
Rectangle {
height: h1_top,
..r
}
);
assert_eq!(
bottom,
Rectangle {
y: y_bottom,
height: h1_bottom,
..r
}
);
}
} }
#[test] #[test]
fn split_vertical() { fn split() {
let a = Axis::Vertical;
// rectangle width, spacing, left width, right x, right width
let cases = vec![ let cases = vec![
// Even height, even spacing
Case::Horizontal {
overall_height: 10.0,
spacing: 2.0,
top_height: 4.0,
bottom_y: 6.0,
bottom_height: 4.0,
},
// Odd height, even spacing
Case::Horizontal {
overall_height: 9.0,
spacing: 2.0,
top_height: 4.0,
bottom_y: 6.0,
bottom_height: 3.0,
},
// Even height, odd spacing
Case::Horizontal {
overall_height: 10.0,
spacing: 1.0,
top_height: 5.0,
bottom_y: 6.0,
bottom_height: 4.0,
},
// Odd height, odd spacing
Case::Horizontal {
overall_height: 9.0,
spacing: 1.0,
top_height: 4.0,
bottom_y: 5.0,
bottom_height: 4.0,
},
// Even width, even spacing // Even width, even spacing
(10.0, 2.0, 4.0, 6.0, 4.0), Case::Vertical {
overall_width: 10.0,
spacing: 2.0,
left_width: 4.0,
right_x: 6.0,
right_width: 4.0,
},
// Odd width, even spacing // Odd width, even spacing
(9.0, 2.0, 4.0, 6.0, 3.0), Case::Vertical {
overall_width: 9.0,
spacing: 2.0,
left_width: 4.0,
right_x: 6.0,
right_width: 3.0,
},
// Even width, odd spacing // Even width, odd spacing
(10.0, 1.0, 5.0, 6.0, 4.0), Case::Vertical {
overall_width: 10.0,
spacing: 1.0,
left_width: 5.0,
right_x: 6.0,
right_width: 4.0,
},
// Odd width, odd spacing // Odd width, odd spacing
(9.0, 1.0, 4.0, 5.0, 4.0), Case::Vertical {
overall_width: 9.0,
spacing: 1.0,
left_width: 4.0,
right_x: 5.0,
right_width: 4.0,
},
]; ];
for case in cases { for case in cases {
let (w0, spacing, w1_left, x_right, w1_right) = case; match case {
let r = Rectangle { Case::Horizontal {
x: 0.0, overall_height,
y: 0.0, spacing,
width: w0, top_height,
height: 10.0, bottom_y,
}; bottom_height,
let (left, right) = a.split(&r, 0.5, spacing); } => {
assert_eq!( let a = Axis::Horizontal;
left, let r = Rectangle {
Rectangle { x: 0.0,
width: w1_left, y: 0.0,
..r width: 10.0,
height: overall_height,
};
let (top, bottom) = a.split(&r, 0.5, spacing);
assert_eq!(
top,
Rectangle {
height: top_height,
..r
}
);
assert_eq!(
bottom,
Rectangle {
y: bottom_y,
height: bottom_height,
..r
}
);
} }
); Case::Vertical {
assert_eq!( overall_width,
right, spacing,
Rectangle { left_width,
x: x_right, right_x,
width: w1_right, right_width,
..r } => {
let a = Axis::Vertical;
let r = Rectangle {
x: 0.0,
y: 0.0,
width: overall_width,
height: 10.0,
};
let (left, right) = a.split(&r, 0.5, spacing);
assert_eq!(
left,
Rectangle {
width: left_width,
..r
}
);
assert_eq!(
right,
Rectangle {
x: right_x,
width: right_width,
..r
}
);
} }
); }
} }
} }
} }