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
This commit is contained in:
Pritesh Nandgaonkar
2018-03-14 09:02:14 -07:00
committed by Facebook Github Bot
parent 3dfb68887d
commit cfb9eeca20

View File

@@ -110,21 +110,23 @@ public class YogaNodeTest {
} }
@Test @Test
public void testMeasureFloatMax() { public void testMeasureFloatBigNumber() {
final YogaNode node = new YogaNode(); final YogaNode node = new YogaNode();
node.setMeasureFunction(new YogaMeasureFunction() { final float bigNumber = (float) 10E5;
public long measure( node.setMeasureFunction(
YogaNode node, new YogaMeasureFunction() {
float width, public long measure(
YogaMeasureMode widthMode, YogaNode node,
float height, float width,
YogaMeasureMode heightMode) { YogaMeasureMode widthMode,
return YogaMeasureOutput.make(Float.MAX_VALUE, Float.MAX_VALUE); float height,
} YogaMeasureMode heightMode) {
}); return YogaMeasureOutput.make(bigNumber, bigNumber);
}
});
node.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED); node.calculateLayout(YogaConstants.UNDEFINED, YogaConstants.UNDEFINED);
assertEquals(Float.MAX_VALUE, node.getLayoutWidth(), 0.01f); assertEquals(bigNumber, node.getLayoutWidth(), 0.01f);
assertEquals(Float.MAX_VALUE, node.getLayoutHeight(), 0.01f); assertEquals(bigNumber, node.getLayoutHeight(), 0.01f);
} }
@Test @Test