/*
 * Copyright (c) Meta Platforms, Inc. and affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */

// @generated by gentest/gentest.rb from gentest/fixtures/YGAlignContentTest.html

extern crate ordered_float;
extern crate yoga;

use yoga::*;

#[test]
fn test_align_content_flex_start() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(130_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root_child0.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root_child2.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root_child3.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root_child4.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(130_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(10_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(10_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(10_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(20_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(130_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(80_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    assert_eq!(30_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(80_f32, root_child2.get_layout_left());
    assert_eq!(10_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(10_f32, root_child2.get_layout_height());

    assert_eq!(30_f32, root_child3.get_layout_left());
    assert_eq!(10_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(80_f32, root_child4.get_layout_left());
    assert_eq!(20_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_flex_start_without_height_on_children() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root_child3.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(0_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(10_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(0_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(10_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(20_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(0_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(50_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(0_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(50_f32, root_child2.get_layout_left());
    assert_eq!(10_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(0_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(10_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(20_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(0_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_flex_start_with_flex() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(120_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    root_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_flex_grow(1_f32);
    root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_flex_grow(1_f32);
    root_child3.set_flex_shrink(1_f32);
    root_child3.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(120_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(40_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(40_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(40_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(80_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(0_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(80_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(40_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(120_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(0_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(120_f32, root.get_layout_height());

    assert_eq!(50_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(40_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(40_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(40_f32, root_child1.get_layout_height());

    assert_eq!(50_f32, root_child2.get_layout_left());
    assert_eq!(80_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(0_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(80_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(40_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(120_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(0_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_flex_end() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_align_content(Align::FlexEnd);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root_child0.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root_child2.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root_child3.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root_child4.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(50_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(10_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(50_f32, root_child2.get_layout_left());
    assert_eq!(20_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(10_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(30_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(40_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(10_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(20_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(10_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(30_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(40_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(0_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(0_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(0_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(0_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(0_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(0_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(0_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(0_f32, root_child0.get_layout_height());

    assert_eq!(100_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(0_f32, root_child1.get_layout_height());

    assert_eq!(100_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(0_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(0_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(0_f32, root_child3.get_layout_height());

    assert_eq!(100_f32, root_child4.get_layout_left());
    assert_eq!(0_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(0_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_spacebetween() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::SpaceBetween);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(130_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root_child0.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root_child2.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root_child3.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root_child4.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(130_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(45_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(10_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(45_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(90_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(130_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(80_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    assert_eq!(30_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(80_f32, root_child2.get_layout_left());
    assert_eq!(45_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(10_f32, root_child2.get_layout_height());

    assert_eq!(30_f32, root_child3.get_layout_left());
    assert_eq!(45_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(80_f32, root_child4.get_layout_left());
    assert_eq!(90_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_spacearound() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::SpaceAround);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(140_f32.into()));
    root.set_height(StyleUnit::Point(120_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root_child0.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root_child2.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root_child3.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root_child4.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(140_f32, root.get_layout_width());
    assert_eq!(120_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(15_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(15_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(55_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(10_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(55_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(95_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(140_f32, root.get_layout_width());
    assert_eq!(120_f32, root.get_layout_height());

    assert_eq!(90_f32, root_child0.get_layout_left());
    assert_eq!(15_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

    assert_eq!(40_f32, root_child1.get_layout_left());
    assert_eq!(15_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(10_f32, root_child1.get_layout_height());

    assert_eq!(90_f32, root_child2.get_layout_left());
    assert_eq!(55_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(10_f32, root_child2.get_layout_height());

    assert_eq!(40_f32, root_child3.get_layout_left());
    assert_eq!(55_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(90_f32, root_child4.get_layout_left());
    assert_eq!(95_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(50_f32, root_child1.get_layout_height());

    assert_eq!(100_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(50_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(50_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(50_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_children() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child0_child0 = Node::new_with_config(&mut config);
    root_child0_child0.set_flex_grow(1_f32);
    root_child0_child0.set_flex_shrink(1_f32);
    root_child0_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child0.insert_child(&mut root_child0_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child0.get_layout_left());
    assert_eq!(0_f32, root_child0_child0.get_layout_top());
    assert_eq!(50_f32, root_child0_child0.get_layout_width());
    assert_eq!(50_f32, root_child0_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(50_f32, root_child1.get_layout_height());

    assert_eq!(100_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(50_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child0.get_layout_left());
    assert_eq!(0_f32, root_child0_child0.get_layout_top());
    assert_eq!(50_f32, root_child0_child0.get_layout_width());
    assert_eq!(50_f32, root_child0_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(50_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(50_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_flex() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_flex_grow(1_f32);
    root_child1.set_flex_shrink(1_f32);
    root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_flex_grow(1_f32);
    root_child3.set_flex_shrink(1_f32);
    root_child3.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(0_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(50_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(0_f32, root_child3.get_layout_top());
    assert_eq!(0_f32, root_child3.get_layout_width());
    assert_eq!(100_f32, root_child3.get_layout_height());

    assert_eq!(100_f32, root_child4.get_layout_left());
    assert_eq!(0_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(100_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(100_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(0_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(50_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(0_f32, root_child3.get_layout_top());
    assert_eq!(0_f32, root_child3.get_layout_width());
    assert_eq!(100_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(0_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(100_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_flex_no_shrink() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_flex_grow(1_f32);
    root_child1.set_flex_shrink(1_f32);
    root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_flex_grow(1_f32);
    root_child3.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(0_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(50_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(0_f32, root_child3.get_layout_top());
    assert_eq!(0_f32, root_child3.get_layout_width());
    assert_eq!(100_f32, root_child3.get_layout_height());

    assert_eq!(100_f32, root_child4.get_layout_left());
    assert_eq!(0_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(100_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(100_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(0_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(50_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(0_f32, root_child3.get_layout_top());
    assert_eq!(0_f32, root_child3.get_layout_width());
    assert_eq!(100_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(0_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(100_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_margin() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_margin(Edge::Left, StyleUnit::Point(10_f32.into()));
    root_child1.set_margin(Edge::Top, StyleUnit::Point(10_f32.into()));
    root_child1.set_margin(Edge::Right, StyleUnit::Point(10_f32.into()));
    root_child1.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into()));
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_margin(Edge::Left, StyleUnit::Point(10_f32.into()));
    root_child3.set_margin(Edge::Top, StyleUnit::Point(10_f32.into()));
    root_child3.set_margin(Edge::Right, StyleUnit::Point(10_f32.into()));
    root_child3.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into()));
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(40_f32, root_child0.get_layout_height());

    assert_eq!(60_f32, root_child1.get_layout_left());
    assert_eq!(10_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(40_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(40_f32, root_child2.get_layout_height());

    assert_eq!(60_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(20_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(80_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(40_f32, root_child0.get_layout_height());

    assert_eq!(40_f32, root_child1.get_layout_left());
    assert_eq!(10_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

    assert_eq!(100_f32, root_child2.get_layout_left());
    assert_eq!(40_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(40_f32, root_child2.get_layout_height());

    assert_eq!(40_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(20_f32, root_child3.get_layout_height());

    assert_eq!(100_f32, root_child4.get_layout_left());
    assert_eq!(80_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_padding() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
    root_child1.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
    root_child1.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
    root_child1.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_padding(Edge::Left, StyleUnit::Point(10_f32.into()));
    root_child3.set_padding(Edge::Top, StyleUnit::Point(10_f32.into()));
    root_child3.set_padding(Edge::Right, StyleUnit::Point(10_f32.into()));
    root_child3.set_padding(Edge::Bottom, StyleUnit::Point(10_f32.into()));
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(50_f32, root_child1.get_layout_height());

    assert_eq!(100_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(50_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(50_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(50_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_single_row() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_fixed_height() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_height(StyleUnit::Point(60_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(80_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(60_f32, root_child1.get_layout_height());

    assert_eq!(100_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(80_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(80_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(20_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(80_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(80_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(60_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(80_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(80_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(20_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(80_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_max_height() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_max_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

    assert_eq!(100_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(50_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(50_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(50_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_row_with_min_height() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(150_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_width(StyleUnit::Point(50_f32.into()));
    root_child1.set_min_height(StyleUnit::Point(80_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_width(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(90_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(90_f32, root_child1.get_layout_height());

    assert_eq!(100_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(90_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(90_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(90_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(150_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(100_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(90_f32, root_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(90_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(90_f32, root_child2.get_layout_height());

    assert_eq!(100_f32, root_child3.get_layout_left());
    assert_eq!(90_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(10_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(90_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(10_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_column() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_align_content(Align::Stretch);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(150_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_height(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child0_child0 = Node::new_with_config(&mut config);
    root_child0_child0.set_flex_grow(1_f32);
    root_child0_child0.set_flex_shrink(1_f32);
    root_child0_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child0.insert_child(&mut root_child0_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_flex_grow(1_f32);
    root_child1.set_flex_shrink(1_f32);
    root_child1.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child1.set_height(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_height(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child2, 2);

    let mut root_child3 = Node::new_with_config(&mut config);
    root_child3.set_height(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_height(StyleUnit::Point(50_f32.into()));
    root.insert_child(&mut root_child4, 4);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(150_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child0.get_layout_left());
    assert_eq!(0_f32, root_child0_child0.get_layout_top());
    assert_eq!(50_f32, root_child0_child0.get_layout_width());
    assert_eq!(50_f32, root_child0_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(50_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(0_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(50_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(0_f32, root_child3.get_layout_left());
    assert_eq!(100_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(50_f32, root_child4.get_layout_left());
    assert_eq!(0_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(150_f32, root.get_layout_height());

    assert_eq!(50_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(50_f32, root_child0.get_layout_width());
    assert_eq!(50_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child0.get_layout_left());
    assert_eq!(0_f32, root_child0_child0.get_layout_top());
    assert_eq!(50_f32, root_child0_child0.get_layout_width());
    assert_eq!(50_f32, root_child0_child0.get_layout_height());

    assert_eq!(50_f32, root_child1.get_layout_left());
    assert_eq!(50_f32, root_child1.get_layout_top());
    assert_eq!(50_f32, root_child1.get_layout_width());
    assert_eq!(0_f32, root_child1.get_layout_height());

    assert_eq!(50_f32, root_child2.get_layout_left());
    assert_eq!(50_f32, root_child2.get_layout_top());
    assert_eq!(50_f32, root_child2.get_layout_width());
    assert_eq!(50_f32, root_child2.get_layout_height());

    assert_eq!(50_f32, root_child3.get_layout_left());
    assert_eq!(100_f32, root_child3.get_layout_top());
    assert_eq!(50_f32, root_child3.get_layout_width());
    assert_eq!(50_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(0_f32, root_child4.get_layout_top());
    assert_eq!(50_f32, root_child4.get_layout_width());
    assert_eq!(50_f32, root_child4.get_layout_height());
}

#[test]
fn test_align_content_stretch_is_not_overriding_align_items() {
    let mut config = Config::new();

    let mut root = Node::new_with_config(&mut config);
    root.set_align_content(Align::Stretch);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_direction(FlexDirection::Row);
    root_child0.set_align_content(Align::Stretch);
    root_child0.set_align_items(Align::Center);
    root_child0.set_width(StyleUnit::Point(100_f32.into()));
    root_child0.set_height(StyleUnit::Point(100_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child0_child0 = Node::new_with_config(&mut config);
    root_child0_child0.set_align_content(Align::Stretch);
    root_child0_child0.set_width(StyleUnit::Point(10_f32.into()));
    root_child0_child0.set_height(StyleUnit::Point(10_f32.into()));
    root_child0.insert_child(&mut root_child0_child0, 0);
    root.calculate_layout(Undefined, Undefined, Direction::LTR);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(100_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child0.get_layout_left());
    assert_eq!(45_f32, root_child0_child0.get_layout_top());
    assert_eq!(10_f32, root_child0_child0.get_layout_width());
    assert_eq!(10_f32, root_child0_child0.get_layout_height());

    root.calculate_layout(Undefined, Undefined, Direction::RTL);

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(0_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(100_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(90_f32, root_child0_child0.get_layout_left());
    assert_eq!(45_f32, root_child0_child0.get_layout_top());
    assert_eq!(10_f32, root_child0_child0.get_layout_width());
    assert_eq!(10_f32, root_child0_child0.get_layout_height());
}
