/*
 * 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/YGGapTest.html

extern crate ordered_float;
extern crate yoga;

use yoga::*;

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_width(StyleUnit::Point(80_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    root_child0.set_flex_shrink(1_f32);
    root_child0.set_flex_basis(StyleUnit::Percent(0_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.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_flex_grow(1_f32);
    root_child2.set_flex_shrink(1_f32);
    root_child2.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(80_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!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(60_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(80_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(60_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_width(StyleUnit::Point(80_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(80_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!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(60_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(80_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(60_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_width(StyleUnit::Point(80_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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.insert_child(&mut root_child1, 1);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_width(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(80_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!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(60_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(80_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(60_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_width(StyleUnit::Point(80_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    root_child0.set_flex_shrink(1_f32);
    root_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child0.set_margin(Edge::Left, StyleUnit::Point(2_f32.into()));
    root_child0.set_margin(Edge::Right, StyleUnit::Point(2_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_margin(Edge::Left, StyleUnit::Point(10_f32.into()));
    root_child1.set_margin(Edge::Right, 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_flex_grow(1_f32);
    root_child2.set_flex_shrink(1_f32);
    root_child2.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child2.set_margin(Edge::Left, StyleUnit::Point(15_f32.into()));
    root_child2.set_margin(Edge::Right, StyleUnit::Point(15_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(80_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

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

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

    assert_eq!(63_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(2_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(80_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

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

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

    assert_eq!(15_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(2_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

#[test]
fn test_column_row_gap_wrapping() {
    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(80_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_f32.into()));
    root_child0.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child1.set_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(20_f32.into()));
    root_child2.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child3.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child4.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child4, 4);

    let mut root_child5 = Node::new_with_config(&mut config);
    root_child5.set_width(StyleUnit::Point(20_f32.into()));
    root_child5.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child5, 5);

    let mut root_child6 = Node::new_with_config(&mut config);
    root_child6.set_width(StyleUnit::Point(20_f32.into()));
    root_child6.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child6, 6);

    let mut root_child7 = Node::new_with_config(&mut config);
    root_child7.set_width(StyleUnit::Point(20_f32.into()));
    root_child7.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child7, 7);

    let mut root_child8 = Node::new_with_config(&mut config);
    root_child8.set_width(StyleUnit::Point(20_f32.into()));
    root_child8.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child8, 8);
    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!(80_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!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

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

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

    assert_eq!(30_f32, root_child4.get_layout_left());
    assert_eq!(40_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    assert_eq!(60_f32, root_child5.get_layout_left());
    assert_eq!(40_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.get_layout_height());

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

    assert_eq!(30_f32, root_child7.get_layout_left());
    assert_eq!(80_f32, root_child7.get_layout_top());
    assert_eq!(20_f32, root_child7.get_layout_width());
    assert_eq!(20_f32, root_child7.get_layout_height());

    assert_eq!(60_f32, root_child8.get_layout_left());
    assert_eq!(80_f32, root_child8.get_layout_top());
    assert_eq!(20_f32, root_child8.get_layout_width());
    assert_eq!(20_f32, root_child8.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!(80_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

    assert_eq!(60_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_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!(20_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!(20_f32, root_child2.get_layout_width());
    assert_eq!(20_f32, root_child2.get_layout_height());

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

    assert_eq!(30_f32, root_child4.get_layout_left());
    assert_eq!(40_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    assert_eq!(0_f32, root_child5.get_layout_left());
    assert_eq!(40_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.get_layout_height());

    assert_eq!(60_f32, root_child6.get_layout_left());
    assert_eq!(80_f32, root_child6.get_layout_top());
    assert_eq!(20_f32, root_child6.get_layout_width());
    assert_eq!(20_f32, root_child6.get_layout_height());

    assert_eq!(30_f32, root_child7.get_layout_left());
    assert_eq!(80_f32, root_child7.get_layout_top());
    assert_eq!(20_f32, root_child7.get_layout_width());
    assert_eq!(20_f32, root_child7.get_layout_height());

    assert_eq!(0_f32, root_child8.get_layout_left());
    assert_eq!(80_f32, root_child8.get_layout_top());
    assert_eq!(20_f32, root_child8.get_layout_width());
    assert_eq!(20_f32, root_child8.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(60_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(80_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

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

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_justify_content(Justify::Center);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(10_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

    assert_eq!(70_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(70_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

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

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_justify_content(Justify::FlexEnd);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(20_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_f32, root_child1.get_layout_height());

    assert_eq!(80_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(60_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_justify_content(Justify::SpaceBetween);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

    assert_eq!(80_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(80_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(40_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_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!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_justify_content(Justify::SpaceAround);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(3_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

    assert_eq!(77_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(77_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

    assert_eq!(3_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_justify_content(Justify::SpaceEvenly);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(5_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

    assert_eq!(75_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(75_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

    assert_eq!(5_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

#[test]
fn test_column_gap_wrap_align_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(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_f32.into()));
    root_child0.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child1.set_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(20_f32.into()));
    root_child2.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child3.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child4.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child4, 4);

    let mut root_child5 = Node::new_with_config(&mut config);
    root_child5.set_width(StyleUnit::Point(20_f32.into()));
    root_child5.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child5, 5);
    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!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

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

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

    assert_eq!(30_f32, root_child4.get_layout_left());
    assert_eq!(40_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    assert_eq!(60_f32, root_child5.get_layout_left());
    assert_eq!(40_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.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!(80_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

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

    assert_eq!(80_f32, root_child3.get_layout_left());
    assert_eq!(40_f32, root_child3.get_layout_top());
    assert_eq!(20_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!(40_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    assert_eq!(20_f32, root_child5.get_layout_left());
    assert_eq!(40_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.get_layout_height());
}

#[test]
fn test_column_gap_wrap_align_center() {
    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::Center);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_f32.into()));
    root_child0.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child1.set_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(20_f32.into()));
    root_child2.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child3.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child4.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child4, 4);

    let mut root_child5 = Node::new_with_config(&mut config);
    root_child5.set_width(StyleUnit::Point(20_f32.into()));
    root_child5.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child5, 5);
    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!(20_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_f32, root_child0.get_layout_height());

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

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

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

    assert_eq!(30_f32, root_child4.get_layout_left());
    assert_eq!(60_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    assert_eq!(60_f32, root_child5.get_layout_left());
    assert_eq!(60_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.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!(80_f32, root_child0.get_layout_left());
    assert_eq!(20_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_f32, root_child0.get_layout_height());

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

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

    assert_eq!(80_f32, root_child3.get_layout_left());
    assert_eq!(60_f32, root_child3.get_layout_top());
    assert_eq!(20_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!(60_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    assert_eq!(20_f32, root_child5.get_layout_left());
    assert_eq!(60_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.get_layout_height());
}

#[test]
fn test_column_gap_wrap_align_flex_end() {
    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::FlexEnd);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_f32.into()));
    root_child0.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child1.set_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(20_f32.into()));
    root_child2.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child3.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child4.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child4, 4);

    let mut root_child5 = Node::new_with_config(&mut config);
    root_child5.set_width(StyleUnit::Point(20_f32.into()));
    root_child5.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child5, 5);
    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!(40_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_f32, root_child0.get_layout_height());

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

    assert_eq!(60_f32, root_child2.get_layout_left());
    assert_eq!(40_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child3.get_layout_width());
    assert_eq!(20_f32, root_child3.get_layout_height());

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

    assert_eq!(60_f32, root_child5.get_layout_left());
    assert_eq!(80_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.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!(80_f32, root_child0.get_layout_left());
    assert_eq!(40_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

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

    assert_eq!(80_f32, root_child3.get_layout_left());
    assert_eq!(80_f32, root_child3.get_layout_top());
    assert_eq!(20_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!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

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

#[test]
fn test_column_gap_wrap_align_space_between() {
    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(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_f32.into()));
    root_child0.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child1.set_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(20_f32.into()));
    root_child2.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child3.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child4.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child4, 4);

    let mut root_child5 = Node::new_with_config(&mut config);
    root_child5.set_width(StyleUnit::Point(20_f32.into()));
    root_child5.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child5, 5);
    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!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

    assert_eq!(60_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_f32, root_child2.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child3.get_layout_width());
    assert_eq!(20_f32, root_child3.get_layout_height());

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

    assert_eq!(60_f32, root_child5.get_layout_left());
    assert_eq!(80_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.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!(80_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

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

    assert_eq!(80_f32, root_child3.get_layout_left());
    assert_eq!(80_f32, root_child3.get_layout_top());
    assert_eq!(20_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!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

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

#[test]
fn test_column_gap_wrap_align_space_around() {
    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(100_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_f32.into()));
    root_child0.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child1.set_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(20_f32.into()));
    root_child2.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child3.set_height(StyleUnit::Point(20_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(20_f32.into()));
    root_child4.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child4, 4);

    let mut root_child5 = Node::new_with_config(&mut config);
    root_child5.set_width(StyleUnit::Point(20_f32.into()));
    root_child5.set_height(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child5, 5);
    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!(10_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_f32, root_child0.get_layout_height());

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

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

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

    assert_eq!(30_f32, root_child4.get_layout_left());
    assert_eq!(70_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    assert_eq!(60_f32, root_child5.get_layout_left());
    assert_eq!(70_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.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!(80_f32, root_child0.get_layout_left());
    assert_eq!(10_f32, root_child0.get_layout_top());
    assert_eq!(20_f32, root_child0.get_layout_width());
    assert_eq!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(20_f32, root_child1.get_layout_height());

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

    assert_eq!(80_f32, root_child3.get_layout_left());
    assert_eq!(70_f32, root_child3.get_layout_top());
    assert_eq!(20_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!(70_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(20_f32, root_child4.get_layout_height());

    assert_eq!(20_f32, root_child5.get_layout_left());
    assert_eq!(70_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(20_f32, root_child5.get_layout_height());
}

#[test]
fn test_column_gap_wrap_align_stretch() {
    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(300_f32.into()));
    root.set_height(StyleUnit::Point(300_f32.into()));
    root.set_gap(Gutter::Column, 5_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    root_child0.set_min_width(StyleUnit::Point(60_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_min_width(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_flex_grow(1_f32);
    root_child2.set_min_width(StyleUnit::Point(60_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_min_width(StyleUnit::Point(60_f32.into()));
    root.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_flex_grow(1_f32);
    root_child4.set_min_width(StyleUnit::Point(60_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!(300_f32, root.get_layout_width());
    assert_eq!(300_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!(71_f32, root_child0.get_layout_width());
    assert_eq!(150_f32, root_child0.get_layout_height());

    assert_eq!(76_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(72_f32, root_child1.get_layout_width());
    assert_eq!(150_f32, root_child1.get_layout_height());

    assert_eq!(153_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(71_f32, root_child2.get_layout_width());
    assert_eq!(150_f32, root_child2.get_layout_height());

    assert_eq!(229_f32, root_child3.get_layout_left());
    assert_eq!(0_f32, root_child3.get_layout_top());
    assert_eq!(71_f32, root_child3.get_layout_width());
    assert_eq!(150_f32, root_child3.get_layout_height());

    assert_eq!(0_f32, root_child4.get_layout_left());
    assert_eq!(150_f32, root_child4.get_layout_top());
    assert_eq!(300_f32, root_child4.get_layout_width());
    assert_eq!(150_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!(300_f32, root.get_layout_width());
    assert_eq!(300_f32, root.get_layout_height());

    assert_eq!(229_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(71_f32, root_child0.get_layout_width());
    assert_eq!(150_f32, root_child0.get_layout_height());

    assert_eq!(153_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(71_f32, root_child1.get_layout_width());
    assert_eq!(150_f32, root_child1.get_layout_height());

    assert_eq!(76_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(72_f32, root_child2.get_layout_width());
    assert_eq!(150_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!(71_f32, root_child3.get_layout_width());
    assert_eq!(150_f32, root_child3.get_layout_height());

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

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_height(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(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(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(30_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(80_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!(10_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(20_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(20_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!(30_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.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!(80_f32, root.get_layout_width());
    assert_eq!(100_f32, root.get_layout_height());

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

    assert_eq!(40_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(20_f32, root_child1.get_layout_width());
    assert_eq!(100_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!(30_f32, root_child2.get_layout_width());
    assert_eq!(100_f32, root_child2.get_layout_height());
}

#[test]
fn test_row_gap_align_items_stretch() {
    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(100_f32.into()));
    root.set_height(StyleUnit::Point(200_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_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(20_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(20_f32.into()));
    root.insert_child(&mut root_child4, 4);

    let mut root_child5 = Node::new_with_config(&mut config);
    root_child5.set_width(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child5, 5);
    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!(200_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!(20_f32, root_child0.get_layout_width());
    assert_eq!(90_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(90_f32, root_child1.get_layout_height());

    assert_eq!(60_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_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!(110_f32, root_child3.get_layout_top());
    assert_eq!(20_f32, root_child3.get_layout_width());
    assert_eq!(90_f32, root_child3.get_layout_height());

    assert_eq!(30_f32, root_child4.get_layout_left());
    assert_eq!(110_f32, root_child4.get_layout_top());
    assert_eq!(20_f32, root_child4.get_layout_width());
    assert_eq!(90_f32, root_child4.get_layout_height());

    assert_eq!(60_f32, root_child5.get_layout_left());
    assert_eq!(110_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(90_f32, root_child5.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!(200_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!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(90_f32, root_child1.get_layout_height());

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

    assert_eq!(80_f32, root_child3.get_layout_left());
    assert_eq!(110_f32, root_child3.get_layout_top());
    assert_eq!(20_f32, root_child3.get_layout_width());
    assert_eq!(90_f32, root_child3.get_layout_height());

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

    assert_eq!(20_f32, root_child5.get_layout_left());
    assert_eq!(110_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(90_f32, root_child5.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_flex_direction(FlexDirection::Row);
    root.set_align_items(Align::FlexEnd);
    root.set_flex_wrap(Wrap::Wrap);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(200_f32.into()));
    root.set_gap(Gutter::Column, 10_f32);
    root.set_gap(Gutter::Row, 20_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_width(StyleUnit::Point(20_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(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(20_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(20_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(20_f32.into()));
    root.insert_child(&mut root_child4, 4);

    let mut root_child5 = Node::new_with_config(&mut config);
    root_child5.set_width(StyleUnit::Point(20_f32.into()));
    root.insert_child(&mut root_child5, 5);
    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!(200_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!(20_f32, root_child0.get_layout_width());
    assert_eq!(0_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(0_f32, root_child1.get_layout_height());

    assert_eq!(60_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(20_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!(20_f32, root_child3.get_layout_top());
    assert_eq!(20_f32, root_child3.get_layout_width());
    assert_eq!(0_f32, root_child3.get_layout_height());

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

    assert_eq!(60_f32, root_child5.get_layout_left());
    assert_eq!(20_f32, root_child5.get_layout_top());
    assert_eq!(20_f32, root_child5.get_layout_width());
    assert_eq!(0_f32, root_child5.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!(200_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!(20_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!(20_f32, root_child1.get_layout_width());
    assert_eq!(0_f32, root_child1.get_layout_height());

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

    assert_eq!(80_f32, root_child3.get_layout_left());
    assert_eq!(20_f32, root_child3.get_layout_top());
    assert_eq!(20_f32, root_child3.get_layout_width());
    assert_eq!(0_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!(20_f32, root_child4.get_layout_width());
    assert_eq!(0_f32, root_child4.get_layout_height());

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

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

    let mut root = Node::new_with_config(&mut config);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(200_f32.into()));
    root.set_gap(Gutter::Row, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    root_child0.set_flex_shrink(1_f32);
    root_child0.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child0.set_margin(Edge::Top, StyleUnit::Point(2_f32.into()));
    root_child0.set_margin(Edge::Bottom, StyleUnit::Point(2_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_margin(Edge::Top, StyleUnit::Point(10_f32.into()));
    root_child1.set_margin(Edge::Bottom, 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_flex_grow(1_f32);
    root_child2.set_flex_shrink(1_f32);
    root_child2.set_flex_basis(StyleUnit::Percent(0_f32.into()));
    root_child2.set_margin(Edge::Top, StyleUnit::Point(15_f32.into()));
    root_child2.set_margin(Edge::Bottom, StyleUnit::Point(15_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(200_f32, root.get_layout_height());

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

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

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(143_f32, root_child2.get_layout_top());
    assert_eq!(100_f32, root_child2.get_layout_width());
    assert_eq!(42_f32, root_child2.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!(200_f32, root.get_layout_height());

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

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

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(143_f32, root_child2.get_layout_top());
    assert_eq!(100_f32, root_child2.get_layout_width());
    assert_eq!(42_f32, root_child2.get_layout_height());
}

#[test]
fn test_row_gap_row_wrap_child_margins() {
    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(100_f32.into()));
    root.set_height(StyleUnit::Point(200_f32.into()));
    root.set_gap(Gutter::Row, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_margin(Edge::Top, StyleUnit::Point(2_f32.into()));
    root_child0.set_margin(Edge::Bottom, StyleUnit::Point(2_f32.into()));
    root_child0.set_width(StyleUnit::Point(60_f32.into()));
    root.insert_child(&mut root_child0, 0);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_margin(Edge::Top, StyleUnit::Point(10_f32.into()));
    root_child1.set_margin(Edge::Bottom, StyleUnit::Point(10_f32.into()));
    root_child1.set_width(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_margin(Edge::Top, StyleUnit::Point(15_f32.into()));
    root_child2.set_margin(Edge::Bottom, StyleUnit::Point(15_f32.into()));
    root_child2.set_width(StyleUnit::Point(60_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(200_f32, root.get_layout_height());

    assert_eq!(0_f32, root_child0.get_layout_left());
    assert_eq!(2_f32, root_child0.get_layout_top());
    assert_eq!(60_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!(24_f32, root_child1.get_layout_top());
    assert_eq!(60_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!(59_f32, root_child2.get_layout_top());
    assert_eq!(60_f32, root_child2.get_layout_width());
    assert_eq!(0_f32, root_child2.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!(200_f32, root.get_layout_height());

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

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

    assert_eq!(40_f32, root_child2.get_layout_left());
    assert_eq!(59_f32, root_child2.get_layout_top());
    assert_eq!(60_f32, root_child2.get_layout_width());
    assert_eq!(0_f32, root_child2.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_gap(Gutter::Row, 10_f32);

    let mut root_child0 = Node::new_with_config(&mut config);
    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_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_height(StyleUnit::Point(30_f32.into()));
    root.insert_child(&mut root_child2, 2);
    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!(80_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!(10_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(20_f32, root_child1.get_layout_top());
    assert_eq!(100_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!(50_f32, root_child2.get_layout_top());
    assert_eq!(100_f32, root_child2.get_layout_width());
    assert_eq!(30_f32, root_child2.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!(80_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!(10_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(20_f32, root_child1.get_layout_top());
    assert_eq!(100_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!(50_f32, root_child2.get_layout_top());
    assert_eq!(100_f32, root_child2.get_layout_width());
    assert_eq!(30_f32, root_child2.get_layout_height());
}
