From c8c6e314e6d22bdfb1444ba72350bac65d6a9498 Mon Sep 17 00:00:00 2001 From: meloalright Date: Wed, 13 Nov 2024 00:40:55 +0800 Subject: [PATCH] feat(mutable): make mutable function mutable --- build.rs | 3 +- include/safe.h | 28 +- src/lib.rs | 77 ++-- src/macros.rs | 2 +- src/safe.cc | 28 +- src/safe.rs | 38 +- tests/taitank_flex_test.rs | 850 ++++++++++++++++++------------------- 7 files changed, 518 insertions(+), 508 deletions(-) diff --git a/build.rs b/build.rs index 91b8fce..59b9ed9 100644 --- a/build.rs +++ b/build.rs @@ -1,7 +1,6 @@ use std::process::Command; fn main() { - Command::new("git") .args(["submodule", "init"]) .status() @@ -27,4 +26,4 @@ fn main() { println!("cargo:rerun-if-changed=src/main.rs"); println!("cargo:rerun-if-changed=src/safe.cc"); println!("cargo:rerun-if-changed=include/safe.h"); -} \ No newline at end of file +} diff --git a/include/safe.h b/include/safe.h index 97ea01a..9e3903d 100644 --- a/include/safe.h +++ b/include/safe.h @@ -21,17 +21,17 @@ class TaitankSafeNode { }; std::unique_ptr node_create(); -void set_width(const std::unique_ptr & node, double width); -void set_height(const std::unique_ptr & node, double width); -void set_direction(const std::unique_ptr & node, int direction); -void set_flex(const std::unique_ptr & node, double flex); -void set_flex_grow(const std::unique_ptr & node, double flex_grow); -void set_flex_shrink(const std::unique_ptr & node, double flex_shrink); -void set_flex_basis(const std::unique_ptr & node, double flex_basis); -void set_flex_direction(const std::unique_ptr & node, int direction); -void insert_child(const std::unique_ptr & node, const std::unique_ptr & child, int index); -void do_layout(const std::unique_ptr & node, double parent_width, double parent_height, int direction); -double get_width(const std::unique_ptr & node); -double get_height(const std::unique_ptr & node); -double get_left(const std::unique_ptr & node); -double get_top(const std::unique_ptr & node); +void set_width(std::unique_ptr & node, double width); +void set_height(std::unique_ptr & node, double width); +void set_direction(std::unique_ptr & node, int direction); +void set_flex(std::unique_ptr & node, double flex); +void set_flex_grow(std::unique_ptr & node, double flex_grow); +void set_flex_shrink(std::unique_ptr & node, double flex_shrink); +void set_flex_basis(std::unique_ptr & node, double flex_basis); +void set_flex_direction(std::unique_ptr & node, int direction); +void insert_child(std::unique_ptr & node, std::unique_ptr & child, int index); +void do_layout(std::unique_ptr & node, double parent_width, double parent_height, int direction); +double get_width(std::unique_ptr & node); +double get_height(std::unique_ptr & node); +double get_left(std::unique_ptr & node); +double get_top(std::unique_ptr & node); diff --git a/src/lib.rs b/src/lib.rs index 65a3fe2..e1dbdcd 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,15 +1,13 @@ -mod safe; pub mod macros; +mod safe; -use safe::ffi; use cxx::UniquePtr; - +use safe::ffi; pub struct TaitankSafeNode { - unique_ptr: UniquePtr + unique_ptr: UniquePtr, } - #[repr(i32)] pub enum Direction { Inherit = 0, @@ -25,51 +23,60 @@ pub enum FlexDirection { FlexDirectionColumnReverse, } - pub fn node_create() -> TaitankSafeNode { TaitankSafeNode { - unique_ptr: ffi::node_create() + unique_ptr: ffi::node_create(), } } -pub fn set_width(node: &TaitankSafeNode, width: f64) { - ffi::set_width(&node.unique_ptr, width); +pub fn set_width(node: &mut TaitankSafeNode, width: f64) { + ffi::set_width(&mut node.unique_ptr, width); } -pub fn set_height(node: &TaitankSafeNode, height: f64) { - ffi::set_height(&node.unique_ptr, height); +pub fn set_height(node: &mut TaitankSafeNode, height: f64) { + ffi::set_height(&mut node.unique_ptr, height); } -pub fn set_direction(node: &TaitankSafeNode, direction: Direction) { - ffi::set_direction(&node.unique_ptr, direction as i32); +pub fn set_direction(node: &mut TaitankSafeNode, direction: Direction) { + ffi::set_direction(&mut node.unique_ptr, direction as i32); } -pub fn set_flex(node: &TaitankSafeNode, flex: f64) { - ffi::set_flex(&node.unique_ptr, flex); +pub fn set_flex(node: &mut TaitankSafeNode, flex: f64) { + ffi::set_flex(&mut node.unique_ptr, flex); } -pub fn set_flex_grow(node: &TaitankSafeNode, flex_grow: f64) { - ffi::set_flex_grow(&node.unique_ptr, flex_grow); +pub fn set_flex_grow(node: &mut TaitankSafeNode, flex_grow: f64) { + ffi::set_flex_grow(&mut node.unique_ptr, flex_grow); } -pub fn set_flex_shrink(node: &TaitankSafeNode, flex_shrink: f64) { - ffi::set_flex_shrink(&node.unique_ptr, flex_shrink); +pub fn set_flex_shrink(node: &mut TaitankSafeNode, flex_shrink: f64) { + ffi::set_flex_shrink(&mut node.unique_ptr, flex_shrink); } -pub fn set_flex_basis(node: &TaitankSafeNode, flex_basis: f64) { - ffi::set_flex_basis(&node.unique_ptr, flex_basis); +pub fn set_flex_basis(node: &mut TaitankSafeNode, flex_basis: f64) { + ffi::set_flex_basis(&mut node.unique_ptr, flex_basis); } -pub fn set_flex_direction(node: &TaitankSafeNode, flex_direction: FlexDirection) { - ffi::set_flex_direction(&node.unique_ptr, flex_direction as i32); +pub fn set_flex_direction(node: &mut TaitankSafeNode, flex_direction: FlexDirection) { + ffi::set_flex_direction(&mut node.unique_ptr, flex_direction as i32); } -pub fn insert_child(node: &TaitankSafeNode, child: &TaitankSafeNode, index: i32) { - ffi::insert_child(&node.unique_ptr, &child.unique_ptr, index); +pub fn insert_child(node: &mut TaitankSafeNode, child: &mut TaitankSafeNode, index: i32) { + ffi::insert_child(&mut node.unique_ptr, &mut child.unique_ptr, index); } -pub fn do_layout(node: &TaitankSafeNode, parent_width: f64, parent_height: f64, direction: Direction) { - ffi::do_layout(&node.unique_ptr, parent_width, parent_height, direction as i32); +pub fn do_layout( + node: &mut TaitankSafeNode, + parent_width: f64, + parent_height: f64, + direction: Direction, +) { + ffi::do_layout( + &mut node.unique_ptr, + parent_width, + parent_height, + direction as i32, + ); } -pub fn get_width(node: &TaitankSafeNode) -> f64 { - ffi::get_width(&node.unique_ptr) +pub fn get_width(node: &mut TaitankSafeNode) -> f64 { + ffi::get_width(&mut node.unique_ptr) } -pub fn get_height(node: &TaitankSafeNode) -> f64 { - ffi::get_height(&node.unique_ptr) +pub fn get_height(node: &mut TaitankSafeNode) -> f64 { + ffi::get_height(&mut node.unique_ptr) } -pub fn get_left(node: &TaitankSafeNode) -> f64 { - ffi::get_left(&node.unique_ptr) +pub fn get_left(node: &mut TaitankSafeNode) -> f64 { + ffi::get_left(&mut node.unique_ptr) } -pub fn get_top(node: &TaitankSafeNode) -> f64 { - ffi::get_top(&node.unique_ptr) +pub fn get_top(node: &mut TaitankSafeNode) -> f64 { + ffi::get_top(&mut node.unique_ptr) } diff --git a/src/macros.rs b/src/macros.rs index 616452a..68f351d 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -15,4 +15,4 @@ macro_rules! layout { ($a:expr) => { do_layout($a, std::f64::NAN, std::f64::NAN, Direction::LTR) }; -} \ No newline at end of file +} diff --git a/src/safe.cc b/src/safe.cc index b9e2cf2..d765b84 100644 --- a/src/safe.cc +++ b/src/safe.cc @@ -16,15 +16,15 @@ std::unique_ptr node_create() { return std::unique_ptr(new TaitankSafeNode()); } -void set_width(const std::unique_ptr & node, double width) { +void set_width(std::unique_ptr & node, double width) { taitank::SetWidth(node->ptr, width); } -void set_height(const std::unique_ptr & node, double height) { +void set_height(std::unique_ptr & node, double height) { taitank::SetHeight(node->ptr, height); } -void set_direction(const std::unique_ptr & node, int direction) { +void set_direction(std::unique_ptr & node, int direction) { switch (direction) { case 0: { taitank::SetDirection(node->ptr, taitank::TaitankDirection::DIRECTION_INHERIT); @@ -41,23 +41,23 @@ void set_direction(const std::unique_ptr & node, int direction) } } -void set_flex(const std::unique_ptr & node, double flex) { +void set_flex(std::unique_ptr & node, double flex) { taitank::SetFlex(node->ptr, flex); } -void set_flex_grow(const std::unique_ptr & node, double flex_grow) { +void set_flex_grow(std::unique_ptr & node, double flex_grow) { taitank::SetFlexGrow(node->ptr, flex_grow); } -void set_flex_shrink(const std::unique_ptr & node, double flex_shrink) { +void set_flex_shrink(std::unique_ptr & node, double flex_shrink) { taitank::SetFlexShrink(node->ptr, flex_shrink); } -void set_flex_basis(const std::unique_ptr & node, double flex_basis) { +void set_flex_basis(std::unique_ptr & node, double flex_basis) { taitank::SetFlexBasis(node->ptr, flex_basis); } -void set_flex_direction(const std::unique_ptr & node, int flex_direction) { +void set_flex_direction(std::unique_ptr & node, int flex_direction) { switch (flex_direction) { case 0: { taitank::SetFlexDirection(node->ptr, taitank::FlexDirection::FLEX_DIRECTION_ROW); @@ -78,11 +78,11 @@ void set_flex_direction(const std::unique_ptr & node, int flex_ } } -void insert_child(const std::unique_ptr & node, const std::unique_ptr & child, int index) { +void insert_child(std::unique_ptr & node, std::unique_ptr & child, int index) { taitank::InsertChild(node->ptr, child->ptr, index); } -void do_layout(const std::unique_ptr & node, double parent_width, double parent_height, int direction) { +void do_layout(std::unique_ptr & node, double parent_width, double parent_height, int direction) { switch (direction) { case 0: { taitank::DoLayout(node->ptr, parent_width, parent_height, taitank::TaitankDirection::DIRECTION_INHERIT); @@ -99,19 +99,19 @@ void do_layout(const std::unique_ptr & node, double parent_widt } } -double get_width(const std::unique_ptr & node) { +double get_width(std::unique_ptr & node) { return taitank::GetWidth(node->ptr); } -double get_height(const std::unique_ptr & node) { +double get_height(std::unique_ptr & node) { return taitank::GetHeight(node->ptr); } -double get_left(const std::unique_ptr & node) { +double get_left(std::unique_ptr & node) { return taitank::GetLeft(node->ptr); } -double get_top(const std::unique_ptr & node) { +double get_top(std::unique_ptr & node) { return taitank::GetTop(node->ptr); } // diff --git a/src/safe.rs b/src/safe.rs index d61f2e2..9d531e6 100644 --- a/src/safe.rs +++ b/src/safe.rs @@ -6,20 +6,28 @@ pub mod ffi { type TaitankSafeNode; fn node_create() -> UniquePtr; - fn set_width(node: &UniquePtr, width: f64); - fn set_height(node: &UniquePtr, height: f64); - fn set_direction(node: &UniquePtr, direction: i32); - fn set_flex(node: &UniquePtr, flex: f64); - fn set_flex_grow(node: &UniquePtr, flex_grow: f64); - fn set_flex_shrink(node: &UniquePtr, flex_shrink: f64); - fn set_flex_basis(node: &UniquePtr, flex_basis: f64); - fn set_flex_direction(node: &UniquePtr, flex_direction: i32); - fn insert_child(node: &UniquePtr, child: &UniquePtr, index: i32); - fn do_layout(node: &UniquePtr, parent_width: f64, parent_height: f64, direction: i32); - fn get_width(node: &UniquePtr) -> f64; - fn get_height(node: &UniquePtr) -> f64; - fn get_left(node: &UniquePtr) -> f64; - fn get_top(node: &UniquePtr) -> f64; + fn set_width(node: &mut UniquePtr, width: f64); + fn set_height(node: &mut UniquePtr, height: f64); + fn set_direction(node: &mut UniquePtr, direction: i32); + fn set_flex(node: &mut UniquePtr, flex: f64); + fn set_flex_grow(node: &mut UniquePtr, flex_grow: f64); + fn set_flex_shrink(node: &mut UniquePtr, flex_shrink: f64); + fn set_flex_basis(node: &mut UniquePtr, flex_basis: f64); + fn set_flex_direction(node: &mut UniquePtr, flex_direction: i32); + fn insert_child( + node: &mut UniquePtr, + child: &mut UniquePtr, + index: i32, + ); + fn do_layout( + node: &mut UniquePtr, + parent_width: f64, + parent_height: f64, + direction: i32, + ); + fn get_width(node: &mut UniquePtr) -> f64; + fn get_height(node: &mut UniquePtr) -> f64; + fn get_left(node: &mut UniquePtr) -> f64; + fn get_top(node: &mut UniquePtr) -> f64; } } - diff --git a/tests/taitank_flex_test.rs b/tests/taitank_flex_test.rs index 5d4b7da..6f4c135 100644 --- a/tests/taitank_flex_test.rs +++ b/tests/taitank_flex_test.rs @@ -5,463 +5,459 @@ mod tests { #[test] fn it_works() { - let node = node_create(); - set_width(&node, 100.0); - set_height(&node, 100.0); - set_direction(&node, Direction::LTR); - layout!(&node); - - assert_eq!(get_left(&node), 0.0); - assert_eq!(get_top(&node), 0.0); - assert_eq!(get_width(&node), 100.0); - assert_eq!(get_height(&node), 100.0); + let mut node = node_create(); + set_width(&mut node, 100.0); + set_height(&mut node, 100.0); + set_direction(&mut node, Direction::LTR); + layout!(&mut node); + + assert_eq!(get_left(&mut node), 0.0); + assert_eq!(get_top(&mut node), 0.0); + assert_eq!(get_width(&mut node), 100.0); + assert_eq!(get_height(&mut node), 100.0); } #[test] fn flex_basis_flex_grow_column() { - let root = node_create(); - set_width(&root, 100.0); - set_height(&root, 100.0); - let root_child0 = node_create(); - set_flex_grow(&root_child0, 1.0); - set_flex_basis(&root_child0, 50.0); - insert_child(&root, &root_child0, 0); - - let root_child1 = node_create(); - set_flex_grow(&root_child1, 1.0); - insert_child(&root, &root_child1, 1); - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::LTR); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(100.0, get_width(&root_child0)); - assert_eq!(75.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(75.0, get_top(&root_child1)); - assert_eq!(100.0, get_width(&root_child1)); - assert_eq!(25.0, get_height(&root_child1)); - - layout!(&root); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(100.0, get_width(&root_child0)); - assert_eq!(75.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(75.0, get_top(&root_child1)); - assert_eq!(100.0, get_width(&root_child1)); - assert_eq!(25.0, get_height(&root_child1)); - + let mut root = node_create(); + set_width(&mut root, 100.0); + set_height(&mut root, 100.0); + let mut root_child0 = node_create(); + set_flex_grow(&mut root_child0, 1.0); + set_flex_basis(&mut root_child0, 50.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_flex_grow(&mut root_child1, 1.0); + insert_child(&mut root, &mut root_child1, 1); + do_layout(&mut root, std::f64::NAN, std::f64::NAN, Direction::LTR); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(100.0, get_width(&mut root_child0)); + assert_eq!(75.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(75.0, get_top(&mut root_child1)); + assert_eq!(100.0, get_width(&mut root_child1)); + assert_eq!(25.0, get_height(&mut root_child1)); + + layout!(&mut root); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(100.0, get_width(&mut root_child0)); + assert_eq!(75.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(75.0, get_top(&mut root_child1)); + assert_eq!(100.0, get_width(&mut root_child1)); + assert_eq!(25.0, get_height(&mut root_child1)); } #[test] fn flex_basis_flex_grow_row() { - let root = node_create(); - set_flex_direction(&root, FlexDirection::FlexDirectionRow); - set_width(&root, 100.0); - set_height(&root, 100.0); - let root_child0 = node_create(); - set_flex_grow(&root_child0, 1.0); - set_flex_basis(&root_child0, 50.0); - insert_child(&root, &root_child0, 0); - - let root_child1 = node_create(); - set_flex_grow(&root_child1, 1.0); - insert_child(&root, &root_child1, 1); - layout!(&root); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(75.0, get_width(&root_child0)); - assert_eq!(100.0, get_height(&root_child0)); - - assert_eq!(75.0, get_left(&root_child1)); - assert_eq!(0.0, get_top(&root_child1)); - assert_eq!(25.0, get_width(&root_child1)); - assert_eq!(100.0, get_height(&root_child1)); - - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::RTL); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(25.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(75.0, get_width(&root_child0)); - assert_eq!(100.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(0.0, get_top(&root_child1)); - assert_eq!(25.0, get_width(&root_child1)); - assert_eq!(100.0, get_height(&root_child1)); - + let mut root = node_create(); + set_flex_direction(&mut root, FlexDirection::FlexDirectionRow); + set_width(&mut root, 100.0); + set_height(&mut root, 100.0); + let mut root_child0 = node_create(); + set_flex_grow(&mut root_child0, 1.0); + set_flex_basis(&mut root_child0, 50.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_flex_grow(&mut root_child1, 1.0); + insert_child(&mut root, &mut root_child1, 1); + layout!(&mut root); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(75.0, get_width(&mut root_child0)); + assert_eq!(100.0, get_height(&mut root_child0)); + + assert_eq!(75.0, get_left(&mut root_child1)); + assert_eq!(0.0, get_top(&mut root_child1)); + assert_eq!(25.0, get_width(&mut root_child1)); + assert_eq!(100.0, get_height(&mut root_child1)); + + do_layout(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(25.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(75.0, get_width(&mut root_child0)); + assert_eq!(100.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(0.0, get_top(&mut root_child1)); + assert_eq!(25.0, get_width(&mut root_child1)); + assert_eq!(100.0, get_height(&mut root_child1)); } #[test] fn flex_basis_flex_shrink_column() { - let root = node_create(); - set_width(&root, 100.0); - set_height(&root, 100.0); - - let root_child0 = node_create(); - set_flex_shrink(&root_child0, 1.0); - set_flex_basis(&root_child0, 100.0); - insert_child(&root, &root_child0, 0); - - let root_child1 = node_create(); - set_flex_basis(&root_child1, 50.0); - insert_child(&root, &root_child1, 1); - - layout!(&root); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(100.0, get_width(&root_child0)); - assert_eq!(50.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(50.0, get_top(&root_child1)); - assert_eq!(100.0, get_width(&root_child1)); - assert_eq!(50.0, get_height(&root_child1)); - - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::RTL); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(100.0, get_width(&root_child0)); - assert_eq!(50.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(50.0, get_top(&root_child1)); - assert_eq!(100.0, get_width(&root_child1)); - assert_eq!(50.0, get_height(&root_child1)); + let mut root = node_create(); + set_width(&mut root, 100.0); + set_height(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_flex_shrink(&mut root_child0, 1.0); + set_flex_basis(&mut root_child0, 100.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_flex_basis(&mut root_child1, 50.0); + insert_child(&mut root, &mut root_child1, 1); + + layout!(&mut root); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(100.0, get_width(&mut root_child0)); + assert_eq!(50.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(50.0, get_top(&mut root_child1)); + assert_eq!(100.0, get_width(&mut root_child1)); + assert_eq!(50.0, get_height(&mut root_child1)); + + do_layout(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(100.0, get_width(&mut root_child0)); + assert_eq!(50.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(50.0, get_top(&mut root_child1)); + assert_eq!(100.0, get_width(&mut root_child1)); + assert_eq!(50.0, get_height(&mut root_child1)); } #[test] fn flex_basis_flex_shrink_row() { - let root = node_create(); - set_flex_direction(&root, FlexDirection::FlexDirectionRow); - set_width(&root, 100.0); - set_height(&root, 100.0); - - let root_child0 = node_create(); - set_flex_shrink(&root_child0, 1.0); - set_flex_basis(&root_child0, 100.0); - insert_child(&root, &root_child0, 0); - - let root_child1 = node_create(); - set_flex_basis(&root_child1, 50.0); - insert_child(&root, &root_child1, 1); - - layout!(&root); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(50.0, get_width(&root_child0)); - assert_eq!(100.0, get_height(&root_child0)); - - assert_eq!(50.0, get_left(&root_child1)); - assert_eq!(0.0, get_top(&root_child1)); - assert_eq!(50.0, get_width(&root_child1)); - assert_eq!(100.0, get_height(&root_child1)); - - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::RTL); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(50.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(50.0, get_width(&root_child0)); - assert_eq!(100.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(0.0, get_top(&root_child1)); - assert_eq!(50.0, get_width(&root_child1)); - assert_eq!(100.0, get_height(&root_child1)); + let mut root = node_create(); + set_flex_direction(&mut root, FlexDirection::FlexDirectionRow); + set_width(&mut root, 100.0); + set_height(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_flex_shrink(&mut root_child0, 1.0); + set_flex_basis(&mut root_child0, 100.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_flex_basis(&mut root_child1, 50.0); + insert_child(&mut root, &mut root_child1, 1); + + layout!(&mut root); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(50.0, get_width(&mut root_child0)); + assert_eq!(100.0, get_height(&mut root_child0)); + + assert_eq!(50.0, get_left(&mut root_child1)); + assert_eq!(0.0, get_top(&mut root_child1)); + assert_eq!(50.0, get_width(&mut root_child1)); + assert_eq!(100.0, get_height(&mut root_child1)); + + do_layout(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(50.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(50.0, get_width(&mut root_child0)); + assert_eq!(100.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(0.0, get_top(&mut root_child1)); + assert_eq!(50.0, get_width(&mut root_child1)); + assert_eq!(100.0, get_height(&mut root_child1)); } - #[test] fn flex_shrink_to_zero() { - let root = node_create(); - set_height(&root, 75.0); - - let root_child0 = node_create(); - set_width(&root_child0, 50.0); - set_height(&root_child0, 50.0); - insert_child(&root, &root_child0, 0); - - let root_child1 = node_create(); - set_flex_shrink(&root_child1, 1.0); - set_width(&root_child1, 50.0); - set_height(&root_child1, 50.0); - insert_child(&root, &root_child1, 1); - - let root_child2 = node_create(); - set_width(&root_child2, 50.0); - set_height(&root_child2, 50.0); - insert_child(&root, &root_child2, 2); - - layout!(&root); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(50.0, get_width(&root)); - assert_eq!(75.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(50.0, get_width(&root_child0)); - assert_eq!(50.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(50.0, get_top(&root_child1)); - assert_eq!(50.0, get_width(&root_child1)); - assert_eq!(0.0, get_height(&root_child1)); - - assert_eq!(0.0, get_left(&root_child2)); - assert_eq!(50.0, get_top(&root_child2)); - assert_eq!(50.0, get_width(&root_child2)); - assert_eq!(50.0, get_height(&root_child2)); - - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::RTL); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(50.0, get_width(&root)); - assert_eq!(75.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(50.0, get_width(&root_child0)); - assert_eq!(50.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(50.0, get_top(&root_child1)); - assert_eq!(50.0, get_width(&root_child1)); - assert_eq!(0.0, get_height(&root_child1)); - - assert_eq!(0.0, get_left(&root_child2)); - assert_eq!(50.0, get_top(&root_child2)); - assert_eq!(50.0, get_width(&root_child2)); - assert_eq!(50.0, get_height(&root_child2)); + let mut root = node_create(); + set_height(&mut root, 75.0); + + let mut root_child0 = node_create(); + set_width(&mut root_child0, 50.0); + set_height(&mut root_child0, 50.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_flex_shrink(&mut root_child1, 1.0); + set_width(&mut root_child1, 50.0); + set_height(&mut root_child1, 50.0); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_width(&mut root_child2, 50.0); + set_height(&mut root_child2, 50.0); + insert_child(&mut root, &mut root_child2, 2); + + layout!(&mut root); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(50.0, get_width(&mut root)); + assert_eq!(75.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(50.0, get_width(&mut root_child0)); + assert_eq!(50.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(50.0, get_top(&mut root_child1)); + assert_eq!(50.0, get_width(&mut root_child1)); + assert_eq!(0.0, get_height(&mut root_child1)); + + assert_eq!(0.0, get_left(&mut root_child2)); + assert_eq!(50.0, get_top(&mut root_child2)); + assert_eq!(50.0, get_width(&mut root_child2)); + assert_eq!(50.0, get_height(&mut root_child2)); + + do_layout(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(50.0, get_width(&mut root)); + assert_eq!(75.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(50.0, get_width(&mut root_child0)); + assert_eq!(50.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(50.0, get_top(&mut root_child1)); + assert_eq!(50.0, get_width(&mut root_child1)); + assert_eq!(0.0, get_height(&mut root_child1)); + + assert_eq!(0.0, get_left(&mut root_child2)); + assert_eq!(50.0, get_top(&mut root_child2)); + assert_eq!(50.0, get_width(&mut root_child2)); + assert_eq!(50.0, get_height(&mut root_child2)); } - #[test] fn flex_basis_overrides_main_size() { - let root = node_create(); - set_width(&root, 100.0); - set_height(&root, 100.0); - - let root_child0 = node_create(); - set_flex_grow(&root_child0, 1.0); - set_flex_basis(&root_child0, 50.0); - set_height(&root_child0, 20.0); - insert_child(&root, &root_child0, 0); - - let root_child1 = node_create(); - set_flex_grow(&root_child1, 1.0); - set_height(&root_child1, 10.0); - insert_child(&root, &root_child1, 1); - - let root_child2 = node_create(); - set_flex_grow(&root_child2, 1.0); - set_height(&root_child2, 10.0); - insert_child(&root, &root_child2, 2); - - layout!(&root); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(100.0, get_width(&root_child0)); - assert_eq!(60.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(60.0, get_top(&root_child1)); - assert_eq!(100.0, get_width(&root_child1)); - assert_eq!(20.0, get_height(&root_child1)); - - assert_eq!(0.0, get_left(&root_child2)); - assert_eq!(80.0, get_top(&root_child2)); - assert_eq!(100.0, get_width(&root_child2)); - assert_eq!(20.0, get_height(&root_child2)); - - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::RTL); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(100.0, get_width(&root_child0)); - assert_eq!(60.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(60.0, get_top(&root_child1)); - assert_eq!(100.0, get_width(&root_child1)); - assert_eq!(20.0, get_height(&root_child1)); - - assert_eq!(0.0, get_left(&root_child2)); - assert_eq!(80.0, get_top(&root_child2)); - assert_eq!(100.0, get_width(&root_child2)); - assert_eq!(20.0, get_height(&root_child2)); + let mut root = node_create(); + set_width(&mut root, 100.0); + set_height(&mut root, 100.0); + + let mut root_child0 = node_create(); + set_flex_grow(&mut root_child0, 1.0); + set_flex_basis(&mut root_child0, 50.0); + set_height(&mut root_child0, 20.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_flex_grow(&mut root_child1, 1.0); + set_height(&mut root_child1, 10.0); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_flex_grow(&mut root_child2, 1.0); + set_height(&mut root_child2, 10.0); + insert_child(&mut root, &mut root_child2, 2); + + layout!(&mut root); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(100.0, get_width(&mut root_child0)); + assert_eq!(60.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(60.0, get_top(&mut root_child1)); + assert_eq!(100.0, get_width(&mut root_child1)); + assert_eq!(20.0, get_height(&mut root_child1)); + + assert_eq!(0.0, get_left(&mut root_child2)); + assert_eq!(80.0, get_top(&mut root_child2)); + assert_eq!(100.0, get_width(&mut root_child2)); + assert_eq!(20.0, get_height(&mut root_child2)); + + do_layout(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(100.0, get_width(&mut root_child0)); + assert_eq!(60.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(60.0, get_top(&mut root_child1)); + assert_eq!(100.0, get_width(&mut root_child1)); + assert_eq!(20.0, get_height(&mut root_child1)); + + assert_eq!(0.0, get_left(&mut root_child2)); + assert_eq!(80.0, get_top(&mut root_child2)); + assert_eq!(100.0, get_width(&mut root_child2)); + assert_eq!(20.0, get_height(&mut root_child2)); } #[test] fn flex_grow_shrink_at_most() { - let root = node_create(); - set_width(&root, 100.0); - set_height(&root, 100.0); - - let root_child0 = node_create(); - insert_child(&root, &root_child0, 0); - - let root_child0_child0 = node_create(); - set_flex_grow(&root_child0_child0, 1.0); - set_flex_shrink(&root_child0_child0, 1.0); - insert_child(&root_child0, &root_child0_child0, 0); - - layout!(&root); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(100.0, get_width(&root_child0)); - assert_eq!(0.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child0_child0)); - assert_eq!(0.0, get_top(&root_child0_child0)); - assert_eq!(100.0, get_width(&root_child0_child0)); - assert_eq!(0.0, get_height(&root_child0_child0)); - - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::RTL); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(100.0, get_width(&root)); - assert_eq!(100.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(100.0, get_width(&root_child0)); - assert_eq!(0.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child0_child0)); - assert_eq!(0.0, get_top(&root_child0_child0)); - assert_eq!(100.0, get_width(&root_child0_child0)); - assert_eq!(0.0, get_height(&root_child0_child0)); + let mut root = node_create(); + set_width(&mut root, 100.0); + set_height(&mut root, 100.0); + + let mut root_child0 = node_create(); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child0_child0 = node_create(); + set_flex_grow(&mut root_child0_child0, 1.0); + set_flex_shrink(&mut root_child0_child0, 1.0); + insert_child(&mut root_child0, &mut root_child0_child0, 0); + + layout!(&mut root); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(100.0, get_width(&mut root_child0)); + assert_eq!(0.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child0_child0)); + assert_eq!(0.0, get_top(&mut root_child0_child0)); + assert_eq!(100.0, get_width(&mut root_child0_child0)); + assert_eq!(0.0, get_height(&mut root_child0_child0)); + + do_layout(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(100.0, get_width(&mut root)); + assert_eq!(100.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(100.0, get_width(&mut root_child0)); + assert_eq!(0.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child0_child0)); + assert_eq!(0.0, get_top(&mut root_child0_child0)); + assert_eq!(100.0, get_width(&mut root_child0_child0)); + assert_eq!(0.0, get_height(&mut root_child0_child0)); } #[test] fn flex_grow_less_than_factor_one() { - let root = node_create(); - set_width(&root, 200.0); - set_height(&root, 500.0); - - let root_child0 = node_create(); - set_flex_grow(&root_child0, 0.2); - set_flex_basis(&root_child0, 40.0); - insert_child(&root, &root_child0, 0); - - let root_child1 = node_create(); - set_flex_grow(&root_child1, 0.2); - insert_child(&root, &root_child1, 1); - - let root_child2 = node_create(); - set_flex_grow(&root_child2, 0.4); - insert_child(&root, &root_child2, 2); - - layout!(&root); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(200.0, get_width(&root)); - assert_eq!(500.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(200.0, get_width(&root_child0)); - assert_eq!(132.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(132.0, get_top(&root_child1)); - assert_eq!(200.0, get_width(&root_child1)); - assert_eq!(92.0, get_height(&root_child1)); - - assert_eq!(0.0, get_left(&root_child2)); - assert_eq!(224.0, get_top(&root_child2)); - assert_eq!(200.0, get_width(&root_child2)); - assert_eq!(184.0, get_height(&root_child2)); - - do_layout(&root, std::f64::NAN, std::f64::NAN, Direction::RTL); - - assert_eq!(0.0, get_left(&root)); - assert_eq!(0.0, get_top(&root)); - assert_eq!(200.0, get_width(&root)); - assert_eq!(500.0, get_height(&root)); - - assert_eq!(0.0, get_left(&root_child0)); - assert_eq!(0.0, get_top(&root_child0)); - assert_eq!(200.0, get_width(&root_child0)); - assert_eq!(132.0, get_height(&root_child0)); - - assert_eq!(0.0, get_left(&root_child1)); - assert_eq!(132.0, get_top(&root_child1)); - assert_eq!(200.0, get_width(&root_child1)); - assert_eq!(92.0, get_height(&root_child1)); - - assert_eq!(0.0, get_left(&root_child2)); - assert_eq!(224.0, get_top(&root_child2)); - assert_eq!(200.0, get_width(&root_child2)); - assert_eq!(184.0, get_height(&root_child2)); + let mut root = node_create(); + set_width(&mut root, 200.0); + set_height(&mut root, 500.0); + + let mut root_child0 = node_create(); + set_flex_grow(&mut root_child0, 0.2); + set_flex_basis(&mut root_child0, 40.0); + insert_child(&mut root, &mut root_child0, 0); + + let mut root_child1 = node_create(); + set_flex_grow(&mut root_child1, 0.2); + insert_child(&mut root, &mut root_child1, 1); + + let mut root_child2 = node_create(); + set_flex_grow(&mut root_child2, 0.4); + insert_child(&mut root, &mut root_child2, 2); + + layout!(&mut root); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(200.0, get_width(&mut root)); + assert_eq!(500.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(200.0, get_width(&mut root_child0)); + assert_eq!(132.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(132.0, get_top(&mut root_child1)); + assert_eq!(200.0, get_width(&mut root_child1)); + assert_eq!(92.0, get_height(&mut root_child1)); + + assert_eq!(0.0, get_left(&mut root_child2)); + assert_eq!(224.0, get_top(&mut root_child2)); + assert_eq!(200.0, get_width(&mut root_child2)); + assert_eq!(184.0, get_height(&mut root_child2)); + + do_layout(&mut root, std::f64::NAN, std::f64::NAN, Direction::RTL); + + assert_eq!(0.0, get_left(&mut root)); + assert_eq!(0.0, get_top(&mut root)); + assert_eq!(200.0, get_width(&mut root)); + assert_eq!(500.0, get_height(&mut root)); + + assert_eq!(0.0, get_left(&mut root_child0)); + assert_eq!(0.0, get_top(&mut root_child0)); + assert_eq!(200.0, get_width(&mut root_child0)); + assert_eq!(132.0, get_height(&mut root_child0)); + + assert_eq!(0.0, get_left(&mut root_child1)); + assert_eq!(132.0, get_top(&mut root_child1)); + assert_eq!(200.0, get_width(&mut root_child1)); + assert_eq!(92.0, get_height(&mut root_child1)); + + assert_eq!(0.0, get_left(&mut root_child2)); + assert_eq!(224.0, get_top(&mut root_child2)); + assert_eq!(200.0, get_width(&mut root_child2)); + assert_eq!(184.0, get_height(&mut root_child2)); } -} \ No newline at end of file +}