summaryrefslogtreecommitdiffstats
path: root/native
diff options
context:
space:
mode:
authorLibravatar Clark Moody <clark@clarkmoody.com>2020-05-26 16:47:29 -0500
committerLibravatar Clark Moody <clark@clarkmoody.com>2020-05-26 16:47:29 -0500
commit9079014974e7dab83d70d2c08adb1dc50a49629c (patch)
tree1ccc392ca0e02decbb1b9865909b4fff9f771f3f /native
parent334dd098170d56c004d7a97bdfbbffe6f63f0ebd (diff)
downloadiced-9079014974e7dab83d70d2c08adb1dc50a49629c.tar.gz
iced-9079014974e7dab83d70d2c08adb1dc50a49629c.tar.bz2
iced-9079014974e7dab83d70d2c08adb1dc50a49629c.zip
Tests for axis split
Diffstat (limited to 'native')
-rw-r--r--native/src/widget/pane_grid/axis.rs87
1 files changed, 87 insertions, 0 deletions
diff --git a/native/src/widget/pane_grid/axis.rs b/native/src/widget/pane_grid/axis.rs
index 7181f9bf..f8c7b661 100644
--- a/native/src/widget/pane_grid/axis.rs
+++ b/native/src/widget/pane_grid/axis.rs
@@ -54,3 +54,90 @@ impl Axis {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn split_horizontal() {
+ let a = Axis::Horizontal;
+ // rectangle height, spacing, top height, bottom y, bottom height
+ let cases = vec![
+ // Even height, even spacing
+ (10.0, 2.0, 4.0, 6.0, 4.0),
+ // Odd height, even spacing
+ (9.0, 2.0, 4.0, 6.0, 3.0),
+ // Even height, odd spacing
+ (10.0, 1.0, 5.0, 6.0, 4.0),
+ // Odd height, odd spacing
+ (9.0, 1.0, 4.0, 5.0, 4.0),
+ ];
+ 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]
+ fn split_vertical() {
+ let a = Axis::Vertical;
+ // rectangle width, spacing, left width, right x, right width
+ let cases = vec![
+ // Even width, even spacing
+ (10.0, 2.0, 4.0, 6.0, 4.0),
+ // Odd width, even spacing
+ (9.0, 2.0, 4.0, 6.0, 3.0),
+ // Even width, odd spacing
+ (10.0, 1.0, 5.0, 6.0, 4.0),
+ // Odd width, odd spacing
+ (9.0, 1.0, 4.0, 5.0, 4.0),
+ ];
+ for case in cases {
+ let (w0, spacing, w1_left, x_right, w1_right) = case;
+ let r = Rectangle {
+ x: 0.0,
+ y: 0.0,
+ width: w0,
+ height: 10.0,
+ };
+ let (left, right) = a.split(&r, 0.5, spacing);
+ assert_eq!(
+ left,
+ Rectangle {
+ width: w1_left,
+ ..r
+ }
+ );
+ assert_eq!(
+ right,
+ Rectangle {
+ x: x_right,
+ width: w1_right,
+ ..r
+ }
+ );
+ }
+ }
+}