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
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