From d0e396d5c55aba2941fc6b27a5997cf19007f8ef Mon Sep 17 00:00:00 2001 From: meloalright Date: Thu, 14 Nov 2024 02:40:41 +0800 Subject: [PATCH] feat(test): add test cases pass by llm --- tests/flex_wrap_test.rs | 639 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 639 insertions(+) diff --git a/tests/flex_wrap_test.rs b/tests/flex_wrap_test.rs index ea1587d..3071ba8 100644 --- a/tests/flex_wrap_test.rs +++ b/tests/flex_wrap_test.rs @@ -470,4 +470,643 @@ mod tests { assert_eq!(100.0, get_height(&mut root_child1)); } + + #[test] + fn flex_wrap_align_stretch_fits_one_row() { + let mut root = node_create(); + set_flex_direction(&mut root, FlexDirection::FlexDirectionRow); + set_flex_wrap(&mut root, FlexWrapNode::FlexWrap); + set_width(&mut root, 150.0); + set_height(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_width(&mut root_child0, 50.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_width(&mut root_child1, 50.0); + insert_child(&mut root, &mut root_child1, 1); + + layout!(&mut root); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 150.0); + assert_eq!(get_height(&mut root), 100.0); + + assert_eq!(get_left(&mut root_child0), 0.0); + assert_eq!(get_top(&mut root_child0), 0.0); + assert_eq!(get_width(&mut root_child0), 50.0); + assert_eq!(get_height(&mut root_child0), 100.0); + + assert_eq!(get_left(&mut root_child1), 50.0); + assert_eq!(get_top(&mut root_child1), 0.0); + assert_eq!(get_width(&mut root_child1), 50.0); + assert_eq!(get_height(&mut root_child1), 100.0); + + layout!(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 150.0); + assert_eq!(get_height(&mut root), 100.0); + + assert_eq!(get_left(&mut root_child0), 100.0); + assert_eq!(get_top(&mut root_child0), 0.0); + assert_eq!(get_width(&mut root_child0), 50.0); + assert_eq!(get_height(&mut root_child0), 100.0); + + assert_eq!(get_left(&mut root_child1), 50.0); + assert_eq!(get_top(&mut root_child1), 0.0); + assert_eq!(get_width(&mut root_child1), 50.0); + assert_eq!(get_height(&mut root_child1), 100.0); + } + + + #[test] + fn wrap_reverse_row_align_content_flex_start() { + let mut root = node_create(); + set_flex_direction(&mut root, FlexDirection::FlexDirectionRow); + set_flex_wrap(&mut root, FlexWrapNode::FlexWrapReverse); + set_width(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_width(&mut root_child0, 30.0); + set_height(&mut root_child0, 10.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_width(&mut root_child1, 30.0); + set_height(&mut root_child1, 20.0); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_width(&mut root_child2, 30.0); + set_height(&mut root_child2, 30.0); + insert_child(&mut root, &mut root_child2, 2); + + let mut root_child3 = node_create(); + set_width(&mut root_child3, 30.0); + set_height(&mut root_child3, 40.0); + insert_child(&mut root, &mut root_child3, 3); + + let mut root_child4 = node_create(); + set_width(&mut root_child4, 30.0); + set_height(&mut root_child4, 50.0); + insert_child(&mut root, &mut root_child4, 4); + + layout!(&mut root); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 100.0); + assert_eq!(get_height(&mut root), 80.0); + + assert_eq!(get_left(&mut root_child0), 0.0); + assert_eq!(get_top(&mut root_child0), 70.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 30.0); + assert_eq!(get_top(&mut root_child1), 60.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 60.0); + assert_eq!(get_top(&mut root_child2), 50.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 0.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 30.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + + layout!(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 100.0); + assert_eq!(get_height(&mut root), 80.0); + + assert_eq!(get_left(&mut root_child0), 70.0); + assert_eq!(get_top(&mut root_child0), 70.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 40.0); + assert_eq!(get_top(&mut root_child1), 60.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 10.0); + assert_eq!(get_top(&mut root_child2), 50.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 70.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 40.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + } + + #[test] + fn wrap_reverse_row_align_content_center() { + let mut root = node_create(); + set_flex_direction(&mut root, FlexDirection::FlexDirectionRow); + set_align_content(&mut root, FlexAlign::FlexAlignCenter); + set_flex_wrap(&mut root, FlexWrapNode::FlexWrapReverse); + set_width(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_width(&mut root_child0, 30.0); + set_height(&mut root_child0, 10.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_width(&mut root_child1, 30.0); + set_height(&mut root_child1, 20.0); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_width(&mut root_child2, 30.0); + set_height(&mut root_child2, 30.0); + insert_child(&mut root, &mut root_child2, 2); + + let mut root_child3 = node_create(); + set_width(&mut root_child3, 30.0); + set_height(&mut root_child3, 40.0); + insert_child(&mut root, &mut root_child3, 3); + + let mut root_child4 = node_create(); + set_width(&mut root_child4, 30.0); + set_height(&mut root_child4, 50.0); + insert_child(&mut root, &mut root_child4, 4); + + layout!(&mut root); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 100.0); + assert_eq!(get_height(&mut root), 80.0); + + assert_eq!(get_left(&mut root_child0), 0.0); + assert_eq!(get_top(&mut root_child0), 70.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 30.0); + assert_eq!(get_top(&mut root_child1), 60.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 60.0); + assert_eq!(get_top(&mut root_child2), 50.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 0.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 30.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + + layout!(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 100.0); + assert_eq!(get_height(&mut root), 80.0); + + assert_eq!(get_left(&mut root_child0), 70.0); + assert_eq!(get_top(&mut root_child0), 70.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 40.0); + assert_eq!(get_top(&mut root_child1), 60.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 10.0); + assert_eq!(get_top(&mut root_child2), 50.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 70.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 40.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + } + + #[test] + fn wrap_reverse_row_single_line_different_size() { + let mut root = node_create(); + set_flex_direction(&mut root, FlexDirection::FlexDirectionRow); + set_flex_wrap(&mut root, FlexWrapNode::FlexWrapReverse); + set_width(&mut root, 300.0); + + let mut root_child0 = node_create(); + set_width(&mut root_child0, 30.0); + set_height(&mut root_child0, 10.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_width(&mut root_child1, 30.0); + set_height(&mut root_child1, 20.0); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_width(&mut root_child2, 30.0); + set_height(&mut root_child2, 30.0); + insert_child(&mut root, &mut root_child2, 2); + + let mut root_child3 = node_create(); + set_width(&mut root_child3, 30.0); + set_height(&mut root_child3, 40.0); + insert_child(&mut root, &mut root_child3, 3); + + let mut root_child4 = node_create(); + set_width(&mut root_child4, 30.0); + set_height(&mut root_child4, 50.0); + insert_child(&mut root, &mut root_child4, 4); + + layout!(&mut root); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 300.0); + assert_eq!(get_height(&mut root), 50.0); + + assert_eq!(get_left(&mut root_child0), 0.0); + assert_eq!(get_top(&mut root_child0), 40.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 30.0); + assert_eq!(get_top(&mut root_child1), 30.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 60.0); + assert_eq!(get_top(&mut root_child2), 20.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 90.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 120.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + + layout!(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 300.0); + assert_eq!(get_height(&mut root), 50.0); + + assert_eq!(get_left(&mut root_child0), 270.0); + assert_eq!(get_top(&mut root_child0), 40.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 240.0); + assert_eq!(get_top(&mut root_child1), 30.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 210.0); + assert_eq!(get_top(&mut root_child2), 20.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 180.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 150.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + } + + #[test] + fn wrap_reverse_row_align_content_stretch() { + let mut root = node_create(); + set_flex_direction(&mut root, FlexDirection::FlexDirectionRow); + set_align_content(&mut root, FlexAlign::FlexAlignStretch); + set_flex_wrap(&mut root, FlexWrapNode::FlexWrapReverse); + set_width(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_width(&mut root_child0, 30.0); + set_height(&mut root_child0, 10.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_width(&mut root_child1, 30.0); + set_height(&mut root_child1, 20.0); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_width(&mut root_child2, 30.0); + set_height(&mut root_child2, 30.0); + insert_child(&mut root, &mut root_child2, 2); + + let mut root_child3 = node_create(); + set_width(&mut root_child3, 30.0); + set_height(&mut root_child3, 40.0); + insert_child(&mut root, &mut root_child3, 3); + + let mut root_child4 = node_create(); + set_width(&mut root_child4, 30.0); + set_height(&mut root_child4, 50.0); + insert_child(&mut root, &mut root_child4, 4); + + layout!(&mut root); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 100.0); + assert_eq!(get_height(&mut root), 80.0); + + assert_eq!(get_left(&mut root_child0), 0.0); + assert_eq!(get_top(&mut root_child0), 70.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 30.0); + assert_eq!(get_top(&mut root_child1), 60.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 60.0); + assert_eq!(get_top(&mut root_child2), 50.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 0.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 30.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + + layout!(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 100.0); + assert_eq!(get_height(&mut root), 80.0); + + assert_eq!(get_left(&mut root_child0), 70.0); + assert_eq!(get_top(&mut root_child0), 70.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 40.0); + assert_eq!(get_top(&mut root_child1), 60.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 10.0); + assert_eq!(get_top(&mut root_child2), 50.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 70.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 40.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + } + + #[test] + fn wrap_reverse_row_align_content_space_around() { + let mut root = node_create(); + set_flex_direction(&mut root, FlexDirection::FlexDirectionRow); + set_align_content(&mut root, FlexAlign::FlexAlignSpaceAround); + set_flex_wrap(&mut root, FlexWrapNode::FlexWrapReverse); + set_width(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_width(&mut root_child0, 30.0); + set_height(&mut root_child0, 10.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_width(&mut root_child1, 30.0); + set_height(&mut root_child1, 20.0); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_width(&mut root_child2, 30.0); + set_height(&mut root_child2, 30.0); + insert_child(&mut root, &mut root_child2, 2); + + let mut root_child3 = node_create(); + set_width(&mut root_child3, 30.0); + set_height(&mut root_child3, 40.0); + insert_child(&mut root, &mut root_child3, 3); + + let mut root_child4 = node_create(); + set_width(&mut root_child4, 30.0); + set_height(&mut root_child4, 50.0); + insert_child(&mut root, &mut root_child4, 4); + + layout!(&mut root); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 100.0); + assert_eq!(get_height(&mut root), 80.0); + + assert_eq!(get_left(&mut root_child0), 0.0); + assert_eq!(get_top(&mut root_child0), 70.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 30.0); + assert_eq!(get_top(&mut root_child1), 60.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 60.0); + assert_eq!(get_top(&mut root_child2), 50.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 0.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 30.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + + layout!(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 100.0); + assert_eq!(get_height(&mut root), 80.0); + + assert_eq!(get_left(&mut root_child0), 70.0); + assert_eq!(get_top(&mut root_child0), 70.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 40.0); + assert_eq!(get_top(&mut root_child1), 60.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 10.0); + assert_eq!(get_top(&mut root_child2), 50.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 70.0); + assert_eq!(get_top(&mut root_child3), 10.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 40.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + } + + #[test] + fn wrap_reverse_column_fixed_size() { + let mut root = node_create(); + set_align_items(&mut root, FlexAlign::FlexAlignCenter); + set_flex_wrap(&mut root, FlexWrapNode::FlexWrapReverse); + set_width(&mut root, 200.0); + set_height(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_width(&mut root_child0, 30.0); + set_height(&mut root_child0, 10.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_width(&mut root_child1, 30.0); + set_height(&mut root_child1, 20.0); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_width(&mut root_child2, 30.0); + set_height(&mut root_child2, 30.0); + insert_child(&mut root, &mut root_child2, 2); + + let mut root_child3 = node_create(); + set_width(&mut root_child3, 30.0); + set_height(&mut root_child3, 40.0); + insert_child(&mut root, &mut root_child3, 3); + + let mut root_child4 = node_create(); + set_width(&mut root_child4, 30.0); + set_height(&mut root_child4, 50.0); + insert_child(&mut root, &mut root_child4, 4); + + layout!(&mut root); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 200.0); + assert_eq!(get_height(&mut root), 100.0); + + assert_eq!(get_left(&mut root_child0), 170.0); + assert_eq!(get_top(&mut root_child0), 0.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 170.0); + assert_eq!(get_top(&mut root_child1), 10.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 170.0); + assert_eq!(get_top(&mut root_child2), 30.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 170.0); + assert_eq!(get_top(&mut root_child3), 60.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 140.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + + layout!(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(get_left(&mut root), 0.0); + assert_eq!(get_top(&mut root), 0.0); + assert_eq!(get_width(&mut root), 200.0); + assert_eq!(get_height(&mut root), 100.0); + + assert_eq!(get_left(&mut root_child0), 0.0); + assert_eq!(get_top(&mut root_child0), 0.0); + assert_eq!(get_width(&mut root_child0), 30.0); + assert_eq!(get_height(&mut root_child0), 10.0); + + assert_eq!(get_left(&mut root_child1), 0.0); + assert_eq!(get_top(&mut root_child1), 10.0); + assert_eq!(get_width(&mut root_child1), 30.0); + assert_eq!(get_height(&mut root_child1), 20.0); + + assert_eq!(get_left(&mut root_child2), 0.0); + assert_eq!(get_top(&mut root_child2), 30.0); + assert_eq!(get_width(&mut root_child2), 30.0); + assert_eq!(get_height(&mut root_child2), 30.0); + + assert_eq!(get_left(&mut root_child3), 0.0); + assert_eq!(get_top(&mut root_child3), 60.0); + assert_eq!(get_width(&mut root_child3), 30.0); + assert_eq!(get_height(&mut root_child3), 40.0); + + assert_eq!(get_left(&mut root_child4), 30.0); + assert_eq!(get_top(&mut root_child4), 0.0); + assert_eq!(get_width(&mut root_child4), 30.0); + assert_eq!(get_height(&mut root_child4), 50.0); + } + }