From cfb9eeca20cdde5566145f56fc096e0b943b39d8 Mon Sep 17 00:00:00 2001 From: Pritesh Nandgaonkar Date: Wed, 14 Mar 2018 09:02:14 -0700 Subject: [PATCH] Fix failing float max test Summary: Earlier YGUndefined was NAN, but recently it was replaced with 10E20 and the check for `isUndefined` is as follows ``` public static boolean isUndefined(float value) { return (Float.compare(value, (float) 10E8) >= 0 || Float.compare(value, (float) -10E8) <= 0); } ``` If the number is in (-inf, -10E8] and [10E8, inf) then it is considered as undefined. Failing test passed values in this range, so thats why the test was failing. Current diff fixes this issue, and passes a big number which is outside the range as the result of measure function. Reviewed By: emilsjolander Differential Revision: D7272325 fbshipit-source-id: 81a77117c65c5dc0cec920f50f0735ec0a7433d1 --- .../tests/com/facebook/yoga/YogaNodeTest.java | 28 ++++++++++--------- 1 file changed, 15 insertions(+), 13 deletions(-) diff --git a/java/tests/com/facebook/yoga/YogaNodeTest.java b/java/tests/com/facebook/yoga/YogaNodeTest.java index 4087232a..1eae117f 100644 --- a/java/tests/com/facebook/yoga/YogaNodeTest.java +++ b/java/tests/com/facebook/yoga/YogaNodeTest.java @@ -110,21 +110,23 @@ public class YogaNodeTest { } @Test - public void testMeasureFloatMax() { + public void testMeasureFloatBigNumber() { final YogaNode node = new YogaNode(); - node.setMeasureFunction(new YogaMeasureFunction() { - public long measure( - YogaNode node, - float width, - YogaMeasureMode widthMode, - float height, - YogaMeasureMode heightMode) { - return YogaMeasureOutput.make(Float.MAX_VALUE, Float.MAX_VALUE); - } - }); + final float bigNumber = (float) 10E5; + node.setMeasureFunction( + new YogaMeasureFunction() { + public long measure( + YogaNode node, + float width, + YogaMeasureMode widthMode, + float height, + YogaMeasureMode heightMode) { + return YogaMeasureOutput.make(bigNumber, bigNumber); + } + }); node.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); - assertEquals(Float.MAX_VALUE, node.getLayoutWidth(), 0.01f); - assertEquals(Float.MAX_VALUE, node.getLayoutHeight(), 0.01f); + assertEquals(bigNumber, node.getLayoutWidth(), 0.01f); + assertEquals(bigNumber, node.getLayoutHeight(), 0.01f); } @Test