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

extern crate ordered_float;
extern crate yoga;

use yoga::*;

#[test]
fn test_rounding_flex_basis_flex_grow_row_width_of_100() {
    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()));

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

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_flex_grow(1_f32);
    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!(33_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

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

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

#[test]
fn test_rounding_flex_basis_flex_grow_row_prime_number_width() {
    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(113_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

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

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_flex_grow(1_f32);
    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.insert_child(&mut root_child3, 3);

    let mut root_child4 = Node::new_with_config(&mut config);
    root_child4.set_flex_grow(1_f32);
    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!(113_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!(23_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

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

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

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

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

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

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

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

#[test]
fn test_rounding_flex_basis_flex_shrink_row() {
    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(101_f32.into()));
    root.set_height(StyleUnit::Point(100_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_shrink(1_f32);
    root_child0.set_flex_basis(StyleUnit::Point(100_f32.into()));
    root.insert_child(&mut root_child0, 0);

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

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_flex_basis(StyleUnit::Point(25_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!(101_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!(51_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

    assert_eq!(51_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(25_f32, root_child1.get_layout_width());
    assert_eq!(100_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!(25_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!(101_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!(51_f32, root_child0.get_layout_width());
    assert_eq!(100_f32, root_child0.get_layout_height());

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

#[test]
fn test_rounding_flex_basis_overrides_main_size() {
    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(113_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::Point(50_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_flex_grow(1_f32);
    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_flex_grow(1_f32);
    root_child2.set_height(StyleUnit::Point(10_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!(113_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!(64_f32, root_child0.get_layout_height());

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

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(89_f32, root_child2.get_layout_top());
    assert_eq!(100_f32, root_child2.get_layout_width());
    assert_eq!(24_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!(113_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!(64_f32, root_child0.get_layout_height());

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

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

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

    let mut root = Node::new_with_config(&mut config);
    root.set_width(StyleUnit::Point(87.4_f32.into()));
    root.set_height(StyleUnit::Point(113.4_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(0.7_f32);
    root_child0.set_flex_basis(StyleUnit::Point(50.3_f32.into()));
    root_child0.set_height(StyleUnit::Point(20.3_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.6_f32);
    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_flex_grow(1.1_f32);
    root_child2.set_height(StyleUnit::Point(10.7_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!(87_f32, root.get_layout_width());
    assert_eq!(113_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!(87_f32, root_child0.get_layout_width());
    assert_eq!(59_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(59_f32, root_child1.get_layout_top());
    assert_eq!(87_f32, root_child1.get_layout_width());
    assert_eq!(30_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(89_f32, root_child2.get_layout_top());
    assert_eq!(87_f32, root_child2.get_layout_width());
    assert_eq!(24_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!(87_f32, root.get_layout_width());
    assert_eq!(113_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!(87_f32, root_child0.get_layout_width());
    assert_eq!(59_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(59_f32, root_child1.get_layout_top());
    assert_eq!(87_f32, root_child1.get_layout_width());
    assert_eq!(30_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(89_f32, root_child2.get_layout_top());
    assert_eq!(87_f32, root_child2.get_layout_width());
    assert_eq!(24_f32, root_child2.get_layout_height());
}

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

    let mut root = Node::new_with_config(&mut config);
    root.set_width(StyleUnit::Point(87.4_f32.into()));
    root.set_height(StyleUnit::Point(113.4_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(0.7_f32);
    root_child0.set_flex_basis(StyleUnit::Point(50.3_f32.into()));
    root_child0.set_height(StyleUnit::Point(20.3_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_basis(StyleUnit::Point(0.3_f32.into()));
    root_child0_child0.set_position(Edge::Bottom, StyleUnit::Point(13.3_f32.into()));
    root_child0_child0.set_height(StyleUnit::Point(9.9_f32.into()));
    root_child0.insert_child(&mut root_child0_child0, 0);

    let mut root_child0_child1 = Node::new_with_config(&mut config);
    root_child0_child1.set_flex_grow(4_f32);
    root_child0_child1.set_flex_basis(StyleUnit::Point(0.3_f32.into()));
    root_child0_child1.set_position(Edge::Top, StyleUnit::Point(13.3_f32.into()));
    root_child0_child1.set_height(StyleUnit::Point(1.1_f32.into()));
    root_child0.insert_child(&mut root_child0_child1, 1);

    let mut root_child1 = Node::new_with_config(&mut config);
    root_child1.set_flex_grow(1.6_f32);
    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_flex_grow(1.1_f32);
    root_child2.set_height(StyleUnit::Point(10.7_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!(87_f32, root.get_layout_width());
    assert_eq!(113_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!(87_f32, root_child0.get_layout_width());
    assert_eq!(59_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child0.get_layout_left());
    assert_eq!(-13_f32, root_child0_child0.get_layout_top());
    assert_eq!(87_f32, root_child0_child0.get_layout_width());
    assert_eq!(12_f32, root_child0_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child1.get_layout_left());
    assert_eq!(25_f32, root_child0_child1.get_layout_top());
    assert_eq!(87_f32, root_child0_child1.get_layout_width());
    assert_eq!(47_f32, root_child0_child1.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(59_f32, root_child1.get_layout_top());
    assert_eq!(87_f32, root_child1.get_layout_width());
    assert_eq!(30_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(89_f32, root_child2.get_layout_top());
    assert_eq!(87_f32, root_child2.get_layout_width());
    assert_eq!(24_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!(87_f32, root.get_layout_width());
    assert_eq!(113_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!(87_f32, root_child0.get_layout_width());
    assert_eq!(59_f32, root_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child0.get_layout_left());
    assert_eq!(-13_f32, root_child0_child0.get_layout_top());
    assert_eq!(87_f32, root_child0_child0.get_layout_width());
    assert_eq!(12_f32, root_child0_child0.get_layout_height());

    assert_eq!(0_f32, root_child0_child1.get_layout_left());
    assert_eq!(25_f32, root_child0_child1.get_layout_top());
    assert_eq!(87_f32, root_child0_child1.get_layout_width());
    assert_eq!(47_f32, root_child0_child1.get_layout_height());

    assert_eq!(0_f32, root_child1.get_layout_left());
    assert_eq!(59_f32, root_child1.get_layout_top());
    assert_eq!(87_f32, root_child1.get_layout_width());
    assert_eq!(30_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(89_f32, root_child2.get_layout_top());
    assert_eq!(87_f32, root_child2.get_layout_width());
    assert_eq!(24_f32, root_child2.get_layout_height());
}

#[test]
fn test_rounding_fractial_input_1() {
    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(113.4_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::Point(50_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_flex_grow(1_f32);
    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_flex_grow(1_f32);
    root_child2.set_height(StyleUnit::Point(10_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!(113_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!(64_f32, root_child0.get_layout_height());

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

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(89_f32, root_child2.get_layout_top());
    assert_eq!(100_f32, root_child2.get_layout_width());
    assert_eq!(24_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!(113_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!(64_f32, root_child0.get_layout_height());

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

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

#[test]
fn test_rounding_fractial_input_2() {
    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(113.6_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::Point(50_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_flex_grow(1_f32);
    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_flex_grow(1_f32);
    root_child2.set_height(StyleUnit::Point(10_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!(114_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!(65_f32, root_child0.get_layout_height());

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

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(89_f32, root_child2.get_layout_top());
    assert_eq!(100_f32, root_child2.get_layout_width());
    assert_eq!(25_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!(114_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!(65_f32, root_child0.get_layout_height());

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

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

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

    let mut root = Node::new_with_config(&mut config);
    root.set_position(Edge::Top, StyleUnit::Point(0.3_f32.into()));
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(113.4_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::Point(50_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_flex_grow(1_f32);
    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_flex_grow(1_f32);
    root_child2.set_height(StyleUnit::Point(10_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!(114_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!(65_f32, root_child0.get_layout_height());

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

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(89_f32, root_child2.get_layout_top());
    assert_eq!(100_f32, root_child2.get_layout_width());
    assert_eq!(25_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!(114_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!(65_f32, root_child0.get_layout_height());

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

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

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

    let mut root = Node::new_with_config(&mut config);
    root.set_position(Edge::Top, StyleUnit::Point(0.7_f32.into()));
    root.set_width(StyleUnit::Point(100_f32.into()));
    root.set_height(StyleUnit::Point(113.4_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::Point(50_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_flex_grow(1_f32);
    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_flex_grow(1_f32);
    root_child2.set_height(StyleUnit::Point(10_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!(1_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(113_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!(64_f32, root_child0.get_layout_height());

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

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

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

    assert_eq!(0_f32, root.get_layout_left());
    assert_eq!(1_f32, root.get_layout_top());
    assert_eq!(100_f32, root.get_layout_width());
    assert_eq!(113_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!(64_f32, root_child0.get_layout_height());

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

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

#[test]
fn test_rounding_inner_node_controversy_horizontal() {
    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(320_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    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_flex_grow(1_f32);
    root_child1.set_height(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child1, 1);

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

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_flex_grow(1_f32);
    root_child2.set_height(StyleUnit::Point(10_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!(320_f32, root.get_layout_width());
    assert_eq!(10_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!(107_f32, root_child0.get_layout_width());
    assert_eq!(10_f32, root_child0.get_layout_height());

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

    assert_eq!(0_f32, root_child1_child0.get_layout_left());
    assert_eq!(0_f32, root_child1_child0.get_layout_top());
    assert_eq!(106_f32, root_child1_child0.get_layout_width());
    assert_eq!(10_f32, root_child1_child0.get_layout_height());

    assert_eq!(213_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(107_f32, root_child2.get_layout_width());
    assert_eq!(10_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!(320_f32, root.get_layout_width());
    assert_eq!(10_f32, root.get_layout_height());

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

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

    assert_eq!(0_f32, root_child1_child0.get_layout_left());
    assert_eq!(0_f32, root_child1_child0.get_layout_top());
    assert_eq!(106_f32, root_child1_child0.get_layout_width());
    assert_eq!(10_f32, root_child1_child0.get_layout_height());

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

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

    let mut root = Node::new_with_config(&mut config);
    root.set_height(StyleUnit::Point(320_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    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_flex_grow(1_f32);
    root_child1.set_width(StyleUnit::Point(10_f32.into()));
    root.insert_child(&mut root_child1, 1);

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

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_flex_grow(1_f32);
    root_child2.set_width(StyleUnit::Point(10_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!(10_f32, root.get_layout_width());
    assert_eq!(320_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!(107_f32, root_child0.get_layout_height());

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

    assert_eq!(0_f32, root_child1_child0.get_layout_left());
    assert_eq!(0_f32, root_child1_child0.get_layout_top());
    assert_eq!(10_f32, root_child1_child0.get_layout_width());
    assert_eq!(106_f32, root_child1_child0.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(213_f32, root_child2.get_layout_top());
    assert_eq!(10_f32, root_child2.get_layout_width());
    assert_eq!(107_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!(10_f32, root.get_layout_width());
    assert_eq!(320_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!(107_f32, root_child0.get_layout_height());

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

    assert_eq!(0_f32, root_child1_child0.get_layout_left());
    assert_eq!(0_f32, root_child1_child0.get_layout_top());
    assert_eq!(10_f32, root_child1_child0.get_layout_width());
    assert_eq!(106_f32, root_child1_child0.get_layout_height());

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

#[test]
fn test_rounding_inner_node_controversy_combined() {
    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(640_f32.into()));
    root.set_height(StyleUnit::Point(320_f32.into()));

    let mut root_child0 = Node::new_with_config(&mut config);
    root_child0.set_flex_grow(1_f32);
    root_child0.set_height(StyleUnit::Percent(100_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_height(StyleUnit::Percent(100_f32.into()));
    root.insert_child(&mut root_child1, 1);

    let mut root_child1_child0 = Node::new_with_config(&mut config);
    root_child1_child0.set_flex_grow(1_f32);
    root_child1_child0.set_width(StyleUnit::Percent(100_f32.into()));
    root_child1.insert_child(&mut root_child1_child0, 0);

    let mut root_child1_child1 = Node::new_with_config(&mut config);
    root_child1_child1.set_flex_grow(1_f32);
    root_child1_child1.set_width(StyleUnit::Percent(100_f32.into()));
    root_child1.insert_child(&mut root_child1_child1, 1);

    let mut root_child1_child1_child0 = Node::new_with_config(&mut config);
    root_child1_child1_child0.set_flex_grow(1_f32);
    root_child1_child1_child0.set_width(StyleUnit::Percent(100_f32.into()));
    root_child1_child1.insert_child(&mut root_child1_child1_child0, 0);

    let mut root_child1_child2 = Node::new_with_config(&mut config);
    root_child1_child2.set_flex_grow(1_f32);
    root_child1_child2.set_width(StyleUnit::Percent(100_f32.into()));
    root_child1.insert_child(&mut root_child1_child2, 2);

    let mut root_child2 = Node::new_with_config(&mut config);
    root_child2.set_flex_grow(1_f32);
    root_child2.set_height(StyleUnit::Percent(100_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!(640_f32, root.get_layout_width());
    assert_eq!(320_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!(213_f32, root_child0.get_layout_width());
    assert_eq!(320_f32, root_child0.get_layout_height());

    assert_eq!(213_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(214_f32, root_child1.get_layout_width());
    assert_eq!(320_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child1_child0.get_layout_left());
    assert_eq!(0_f32, root_child1_child0.get_layout_top());
    assert_eq!(214_f32, root_child1_child0.get_layout_width());
    assert_eq!(107_f32, root_child1_child0.get_layout_height());

    assert_eq!(0_f32, root_child1_child1.get_layout_left());
    assert_eq!(107_f32, root_child1_child1.get_layout_top());
    assert_eq!(214_f32, root_child1_child1.get_layout_width());
    assert_eq!(106_f32, root_child1_child1.get_layout_height());

    assert_eq!(0_f32, root_child1_child1_child0.get_layout_left());
    assert_eq!(0_f32, root_child1_child1_child0.get_layout_top());
    assert_eq!(214_f32, root_child1_child1_child0.get_layout_width());
    assert_eq!(106_f32, root_child1_child1_child0.get_layout_height());

    assert_eq!(0_f32, root_child1_child2.get_layout_left());
    assert_eq!(213_f32, root_child1_child2.get_layout_top());
    assert_eq!(214_f32, root_child1_child2.get_layout_width());
    assert_eq!(107_f32, root_child1_child2.get_layout_height());

    assert_eq!(427_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(213_f32, root_child2.get_layout_width());
    assert_eq!(320_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!(640_f32, root.get_layout_width());
    assert_eq!(320_f32, root.get_layout_height());

    assert_eq!(427_f32, root_child0.get_layout_left());
    assert_eq!(0_f32, root_child0.get_layout_top());
    assert_eq!(213_f32, root_child0.get_layout_width());
    assert_eq!(320_f32, root_child0.get_layout_height());

    assert_eq!(213_f32, root_child1.get_layout_left());
    assert_eq!(0_f32, root_child1.get_layout_top());
    assert_eq!(214_f32, root_child1.get_layout_width());
    assert_eq!(320_f32, root_child1.get_layout_height());

    assert_eq!(0_f32, root_child1_child0.get_layout_left());
    assert_eq!(0_f32, root_child1_child0.get_layout_top());
    assert_eq!(214_f32, root_child1_child0.get_layout_width());
    assert_eq!(107_f32, root_child1_child0.get_layout_height());

    assert_eq!(0_f32, root_child1_child1.get_layout_left());
    assert_eq!(107_f32, root_child1_child1.get_layout_top());
    assert_eq!(214_f32, root_child1_child1.get_layout_width());
    assert_eq!(106_f32, root_child1_child1.get_layout_height());

    assert_eq!(0_f32, root_child1_child1_child0.get_layout_left());
    assert_eq!(0_f32, root_child1_child1_child0.get_layout_top());
    assert_eq!(214_f32, root_child1_child1_child0.get_layout_width());
    assert_eq!(106_f32, root_child1_child1_child0.get_layout_height());

    assert_eq!(0_f32, root_child1_child2.get_layout_left());
    assert_eq!(213_f32, root_child1_child2.get_layout_top());
    assert_eq!(214_f32, root_child1_child2.get_layout_width());
    assert_eq!(107_f32, root_child1_child2.get_layout_height());

    assert_eq!(0_f32, root_child2.get_layout_left());
    assert_eq!(0_f32, root_child2.get_layout_top());
    assert_eq!(213_f32, root_child2.get_layout_width());
    assert_eq!(320_f32, root_child2.get_layout_height());
}
