Files
yoga/csharp/tests/Facebook.Yoga/YGRoundingTest.cs
Nick Gerleman 7e96b65790 Import "Fix percent absolute position and size calcuate different with web" behind experimental feature (#1028) (#1201)
Summary:
Fixes https://github.com/facebook/yoga/issues/850

https://github.com/facebook/yoga/issues/850 describes a conformance issue where positioning of an absolute child using percentages is not calculated against the correct box size.

This takes the fix for that in https://github.com/facebook/yoga/pull/1028, regenerates tests, and fixes tests so that the experimental feature can be enabled. Goal is to run this as an experiment internally to see if we can enable by default.

Changelog:
[Internal]

Pull Request resolved: https://github.com/facebook/yoga/pull/1201

Reviewed By: yungsters

Differential Revision: D42282358

Pulled By: NickGerleman

fbshipit-source-id: 57c0dd9b0f1c47cb9335ff6e13d44b4646e5fa58
2023-01-08 13:41:27 -08:00

1112 lines
46 KiB
C#

/*
* 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
using System;
using NUnit.Framework;
namespace Facebook.Yoga
{
[TestFixture]
public class YGRoundingTest
{
[Test]
public void Test_rounding_flex_basis_flex_grow_row_width_of_100()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 100;
root.Height = 100;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(33f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
Assert.AreEqual(33f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(34f, root_child1.LayoutWidth);
Assert.AreEqual(100f, root_child1.LayoutHeight);
Assert.AreEqual(67f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(33f, root_child2.LayoutWidth);
Assert.AreEqual(100f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(67f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(33f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
Assert.AreEqual(33f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(34f, root_child1.LayoutWidth);
Assert.AreEqual(100f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(33f, root_child2.LayoutWidth);
Assert.AreEqual(100f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_flex_basis_flex_grow_row_prime_number_width()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 113;
root.Height = 100;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root.Insert(2, root_child2);
YogaNode root_child3 = new YogaNode(config);
root_child3.FlexGrow = 1;
root.Insert(3, root_child3);
YogaNode root_child4 = new YogaNode(config);
root_child4.FlexGrow = 1;
root.Insert(4, root_child4);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(113f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(23f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
Assert.AreEqual(23f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(22f, root_child1.LayoutWidth);
Assert.AreEqual(100f, root_child1.LayoutHeight);
Assert.AreEqual(45f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(23f, root_child2.LayoutWidth);
Assert.AreEqual(100f, root_child2.LayoutHeight);
Assert.AreEqual(68f, root_child3.LayoutX);
Assert.AreEqual(0f, root_child3.LayoutY);
Assert.AreEqual(22f, root_child3.LayoutWidth);
Assert.AreEqual(100f, root_child3.LayoutHeight);
Assert.AreEqual(90f, root_child4.LayoutX);
Assert.AreEqual(0f, root_child4.LayoutY);
Assert.AreEqual(23f, root_child4.LayoutWidth);
Assert.AreEqual(100f, root_child4.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(113f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(90f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(23f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
Assert.AreEqual(68f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(22f, root_child1.LayoutWidth);
Assert.AreEqual(100f, root_child1.LayoutHeight);
Assert.AreEqual(45f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(23f, root_child2.LayoutWidth);
Assert.AreEqual(100f, root_child2.LayoutHeight);
Assert.AreEqual(23f, root_child3.LayoutX);
Assert.AreEqual(0f, root_child3.LayoutY);
Assert.AreEqual(22f, root_child3.LayoutWidth);
Assert.AreEqual(100f, root_child3.LayoutHeight);
Assert.AreEqual(0f, root_child4.LayoutX);
Assert.AreEqual(0f, root_child4.LayoutY);
Assert.AreEqual(23f, root_child4.LayoutWidth);
Assert.AreEqual(100f, root_child4.LayoutHeight);
}
[Test]
public void Test_rounding_flex_basis_flex_shrink_row()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 101;
root.Height = 100;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexShrink = 1;
root_child0.FlexBasis = 100;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexBasis = 25;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexBasis = 25;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(101f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(51f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
Assert.AreEqual(51f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(25f, root_child1.LayoutWidth);
Assert.AreEqual(100f, root_child1.LayoutHeight);
Assert.AreEqual(76f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(25f, root_child2.LayoutWidth);
Assert.AreEqual(100f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(101f, root.LayoutWidth);
Assert.AreEqual(100f, root.LayoutHeight);
Assert.AreEqual(50f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(51f, root_child0.LayoutWidth);
Assert.AreEqual(100f, root_child0.LayoutHeight);
Assert.AreEqual(25f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(25f, root_child1.LayoutWidth);
Assert.AreEqual(100f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(25f, root_child2.LayoutWidth);
Assert.AreEqual(100f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_flex_basis_overrides_main_size()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.Width = 100;
root.Height = 113;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.FlexBasis = 50;
root_child0.Height = 20;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(64f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(25f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(64f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(25f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_total_fractial()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.Width = 87.4f;
root.Height = 113.4f;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 0.7f;
root_child0.FlexBasis = 50.3f;
root_child0.Height = 20.3f;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1.6f;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1.1f;
root_child2.Height = 10.7f;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(87f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(87f, root_child0.LayoutWidth);
Assert.AreEqual(59f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(59f, root_child1.LayoutY);
Assert.AreEqual(87f, root_child1.LayoutWidth);
Assert.AreEqual(30f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(87f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(87f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(87f, root_child0.LayoutWidth);
Assert.AreEqual(59f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(59f, root_child1.LayoutY);
Assert.AreEqual(87f, root_child1.LayoutWidth);
Assert.AreEqual(30f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(87f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_total_fractial_nested()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.Width = 87.4f;
root.Height = 113.4f;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 0.7f;
root_child0.FlexBasis = 50.3f;
root_child0.Height = 20.3f;
root.Insert(0, root_child0);
YogaNode root_child0_child0 = new YogaNode(config);
root_child0_child0.FlexGrow = 1;
root_child0_child0.FlexBasis = 0.3f;
root_child0_child0.Bottom = 13.3f;
root_child0_child0.Height = 9.9f;
root_child0.Insert(0, root_child0_child0);
YogaNode root_child0_child1 = new YogaNode(config);
root_child0_child1.FlexGrow = 4;
root_child0_child1.FlexBasis = 0.3f;
root_child0_child1.Top = 13.3f;
root_child0_child1.Height = 1.1f;
root_child0.Insert(1, root_child0_child1);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1.6f;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1.1f;
root_child2.Height = 10.7f;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(87f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(87f, root_child0.LayoutWidth);
Assert.AreEqual(59f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(-13f, root_child0_child0.LayoutY);
Assert.AreEqual(87f, root_child0_child0.LayoutWidth);
Assert.AreEqual(12f, root_child0_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child1.LayoutX);
Assert.AreEqual(25f, root_child0_child1.LayoutY);
Assert.AreEqual(87f, root_child0_child1.LayoutWidth);
Assert.AreEqual(47f, root_child0_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(59f, root_child1.LayoutY);
Assert.AreEqual(87f, root_child1.LayoutWidth);
Assert.AreEqual(30f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(87f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(87f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(87f, root_child0.LayoutWidth);
Assert.AreEqual(59f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child0.LayoutX);
Assert.AreEqual(-13f, root_child0_child0.LayoutY);
Assert.AreEqual(87f, root_child0_child0.LayoutWidth);
Assert.AreEqual(12f, root_child0_child0.LayoutHeight);
Assert.AreEqual(0f, root_child0_child1.LayoutX);
Assert.AreEqual(25f, root_child0_child1.LayoutY);
Assert.AreEqual(87f, root_child0_child1.LayoutWidth);
Assert.AreEqual(47f, root_child0_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(59f, root_child1.LayoutY);
Assert.AreEqual(87f, root_child1.LayoutWidth);
Assert.AreEqual(30f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(87f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_fractial_input_1()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.Width = 100;
root.Height = 113.4f;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.FlexBasis = 50;
root_child0.Height = 20;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(64f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(25f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(64f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(25f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_fractial_input_2()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.Width = 100;
root.Height = 113.6f;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.FlexBasis = 50;
root_child0.Height = 20;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(114f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(65f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(65f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(24f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(25f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(114f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(65f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(65f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(24f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(25f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_fractial_input_3()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.Top = 0.3f;
root.Width = 100;
root.Height = 113.4f;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.FlexBasis = 50;
root_child0.Height = 20;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(114f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(65f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(24f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(25f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(114f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(65f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(24f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(25f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_fractial_input_4()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.Top = 0.7f;
root.Width = 100;
root.Height = 113.4f;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.FlexBasis = 50;
root_child0.Height = 20;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(1f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(64f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(25f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(1f, root.LayoutY);
Assert.AreEqual(100f, root.LayoutWidth);
Assert.AreEqual(113f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(100f, root_child0.LayoutWidth);
Assert.AreEqual(64f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(64f, root_child1.LayoutY);
Assert.AreEqual(100f, root_child1.LayoutWidth);
Assert.AreEqual(25f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(89f, root_child2.LayoutY);
Assert.AreEqual(100f, root_child2.LayoutWidth);
Assert.AreEqual(24f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_inner_node_controversy_horizontal()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 320;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.Height = 10;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 10;
root.Insert(1, root_child1);
YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.FlexGrow = 1;
root_child1_child0.Height = 10;
root_child1.Insert(0, root_child1_child0);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(320f, root.LayoutWidth);
Assert.AreEqual(10f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(107f, root_child0.LayoutWidth);
Assert.AreEqual(10f, root_child0.LayoutHeight);
Assert.AreEqual(107f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(106f, root_child1.LayoutWidth);
Assert.AreEqual(10f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(106f, root_child1_child0.LayoutWidth);
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
Assert.AreEqual(213f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(107f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(320f, root.LayoutWidth);
Assert.AreEqual(10f, root.LayoutHeight);
Assert.AreEqual(213f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(107f, root_child0.LayoutWidth);
Assert.AreEqual(10f, root_child0.LayoutHeight);
Assert.AreEqual(107f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(106f, root_child1.LayoutWidth);
Assert.AreEqual(10f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(106f, root_child1_child0.LayoutWidth);
Assert.AreEqual(10f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(107f, root_child2.LayoutWidth);
Assert.AreEqual(10f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_inner_node_controversy_vertical()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.Height = 320;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.Width = 10;
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Width = 10;
root.Insert(1, root_child1);
YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.FlexGrow = 1;
root_child1_child0.Width = 10;
root_child1.Insert(0, root_child1_child0);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Width = 10;
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(10f, root.LayoutWidth);
Assert.AreEqual(320f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(10f, root_child0.LayoutWidth);
Assert.AreEqual(107f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(107f, root_child1.LayoutY);
Assert.AreEqual(10f, root_child1.LayoutWidth);
Assert.AreEqual(106f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(10f, root_child1_child0.LayoutWidth);
Assert.AreEqual(106f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(213f, root_child2.LayoutY);
Assert.AreEqual(10f, root_child2.LayoutWidth);
Assert.AreEqual(107f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(10f, root.LayoutWidth);
Assert.AreEqual(320f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(10f, root_child0.LayoutWidth);
Assert.AreEqual(107f, root_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1.LayoutX);
Assert.AreEqual(107f, root_child1.LayoutY);
Assert.AreEqual(10f, root_child1.LayoutWidth);
Assert.AreEqual(106f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(10f, root_child1_child0.LayoutWidth);
Assert.AreEqual(106f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(213f, root_child2.LayoutY);
Assert.AreEqual(10f, root_child2.LayoutWidth);
Assert.AreEqual(107f, root_child2.LayoutHeight);
}
[Test]
public void Test_rounding_inner_node_controversy_combined()
{
YogaConfig config = new YogaConfig();
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.AbsolutePercentageAgainstPaddingEdge, true);
config.SetExperimentalFeatureEnabled(YogaExperimentalFeature.FixAbsoluteTrailingColumnMargin, true);
YogaNode root = new YogaNode(config);
root.FlexDirection = YogaFlexDirection.Row;
root.Width = 640;
root.Height = 320;
YogaNode root_child0 = new YogaNode(config);
root_child0.FlexGrow = 1;
root_child0.Height = 100.Percent();
root.Insert(0, root_child0);
YogaNode root_child1 = new YogaNode(config);
root_child1.FlexGrow = 1;
root_child1.Height = 100.Percent();
root.Insert(1, root_child1);
YogaNode root_child1_child0 = new YogaNode(config);
root_child1_child0.FlexGrow = 1;
root_child1_child0.Width = 100.Percent();
root_child1.Insert(0, root_child1_child0);
YogaNode root_child1_child1 = new YogaNode(config);
root_child1_child1.FlexGrow = 1;
root_child1_child1.Width = 100.Percent();
root_child1.Insert(1, root_child1_child1);
YogaNode root_child1_child1_child0 = new YogaNode(config);
root_child1_child1_child0.FlexGrow = 1;
root_child1_child1_child0.Width = 100.Percent();
root_child1_child1.Insert(0, root_child1_child1_child0);
YogaNode root_child1_child2 = new YogaNode(config);
root_child1_child2.FlexGrow = 1;
root_child1_child2.Width = 100.Percent();
root_child1.Insert(2, root_child1_child2);
YogaNode root_child2 = new YogaNode(config);
root_child2.FlexGrow = 1;
root_child2.Height = 100.Percent();
root.Insert(2, root_child2);
root.StyleDirection = YogaDirection.LTR;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(640f, root.LayoutWidth);
Assert.AreEqual(320f, root.LayoutHeight);
Assert.AreEqual(0f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(213f, root_child0.LayoutWidth);
Assert.AreEqual(320f, root_child0.LayoutHeight);
Assert.AreEqual(213f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(214f, root_child1.LayoutWidth);
Assert.AreEqual(320f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(214f, root_child1_child0.LayoutWidth);
Assert.AreEqual(107f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1_child1.LayoutX);
Assert.AreEqual(107f, root_child1_child1.LayoutY);
Assert.AreEqual(214f, root_child1_child1.LayoutWidth);
Assert.AreEqual(106f, root_child1_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child1_child0.LayoutY);
Assert.AreEqual(214f, root_child1_child1_child0.LayoutWidth);
Assert.AreEqual(106f, root_child1_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1_child2.LayoutX);
Assert.AreEqual(213f, root_child1_child2.LayoutY);
Assert.AreEqual(214f, root_child1_child2.LayoutWidth);
Assert.AreEqual(107f, root_child1_child2.LayoutHeight);
Assert.AreEqual(427f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(213f, root_child2.LayoutWidth);
Assert.AreEqual(320f, root_child2.LayoutHeight);
root.StyleDirection = YogaDirection.RTL;
root.CalculateLayout();
Assert.AreEqual(0f, root.LayoutX);
Assert.AreEqual(0f, root.LayoutY);
Assert.AreEqual(640f, root.LayoutWidth);
Assert.AreEqual(320f, root.LayoutHeight);
Assert.AreEqual(427f, root_child0.LayoutX);
Assert.AreEqual(0f, root_child0.LayoutY);
Assert.AreEqual(213f, root_child0.LayoutWidth);
Assert.AreEqual(320f, root_child0.LayoutHeight);
Assert.AreEqual(213f, root_child1.LayoutX);
Assert.AreEqual(0f, root_child1.LayoutY);
Assert.AreEqual(214f, root_child1.LayoutWidth);
Assert.AreEqual(320f, root_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child0.LayoutY);
Assert.AreEqual(214f, root_child1_child0.LayoutWidth);
Assert.AreEqual(107f, root_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1_child1.LayoutX);
Assert.AreEqual(107f, root_child1_child1.LayoutY);
Assert.AreEqual(214f, root_child1_child1.LayoutWidth);
Assert.AreEqual(106f, root_child1_child1.LayoutHeight);
Assert.AreEqual(0f, root_child1_child1_child0.LayoutX);
Assert.AreEqual(0f, root_child1_child1_child0.LayoutY);
Assert.AreEqual(214f, root_child1_child1_child0.LayoutWidth);
Assert.AreEqual(106f, root_child1_child1_child0.LayoutHeight);
Assert.AreEqual(0f, root_child1_child2.LayoutX);
Assert.AreEqual(213f, root_child1_child2.LayoutY);
Assert.AreEqual(214f, root_child1_child2.LayoutWidth);
Assert.AreEqual(107f, root_child1_child2.LayoutHeight);
Assert.AreEqual(0f, root_child2.LayoutX);
Assert.AreEqual(0f, root_child2.LayoutY);
Assert.AreEqual(213f, root_child2.LayoutWidth);
Assert.AreEqual(320f, root_child2.LayoutHeight);
}
}
}