use of org.ballerinalang.model.values.BFloat in project ballerina by ballerina-lang.
the class ValueTypeCastExprTest method testFloatToBoolean.
@Test
public void testFloatToBoolean() {
BValue[] args = { new BFloat(1.0f) };
BValue[] returns = BRunUtil.invoke(result, "floatToBoolean", args);
Assert.assertTrue(returns[0] instanceof BBoolean);
final boolean expected = true;
Assert.assertEquals(((BBoolean) returns[0]).booleanValue(), expected);
}
use of org.ballerinalang.model.values.BFloat in project ballerina by ballerina-lang.
the class UnaryExprTest method floatUnaryExprTest.
@Test(description = "Test float unary negative expression")
public void floatUnaryExprTest() {
BValue[] args = {};
BValue[] returns = BRunUtil.invoke(result, "negativeFloatTest", args);
Assert.assertEquals(returns.length, 2);
BFloat x = (BFloat) returns[0];
Assert.assertSame(x.getClass(), BFloat.class, "Invalid class type returned.");
Assert.assertEquals(x.floatValue(), -5.0D, "Invalid value returned.");
BFloat y = (BFloat) returns[1];
Assert.assertSame(y.getClass(), BFloat.class, "Invalid class type returned.");
Assert.assertEquals(y.floatValue(), 5.0D, "Invalid value returned.");
}
use of org.ballerinalang.model.values.BFloat in project ballerina by ballerina-lang.
the class DivisionOperationTest method testFloatDivideByInt.
@Test(description = "Test float number division by integer")
public void testFloatDivideByInt() {
double a = Float.MAX_VALUE;
int b = 123456789;
double expectedResult = a / b;
BValue[] args = { new BFloat(a), new BInteger(b) };
BValue[] returns = BRunUtil.invoke(result, "floatDivideByInt", args);
Assert.assertEquals(returns.length, 1);
Assert.assertSame(returns[0].getClass(), BFloat.class, "Return type of the division is invalid");
double actualResult = ((BFloat) returns[0]).floatValue();
Assert.assertEquals(actualResult, expectedResult, DELTA, "Result of the division operation is incorrect");
}
use of org.ballerinalang.model.values.BFloat in project ballerina by ballerina-lang.
the class DivisionOperationTest method testFloatDivideExpr.
@Test(description = "Test two float divide expression")
public void testFloatDivideExpr() {
float a = 8.5f;
float b = 4.1f;
double expectedResult = a / b;
BValue[] args = { new BFloat(a), new BFloat(b) };
BValue[] returns = BRunUtil.invoke(result, "floatDivide", args);
Assert.assertEquals(returns.length, 1);
Assert.assertSame(returns[0].getClass(), BFloat.class);
double actual = ((BFloat) returns[0]).floatValue();
Assert.assertEquals(actual, expectedResult, DELTA);
}
use of org.ballerinalang.model.values.BFloat in project ballerina by ballerina-lang.
the class DivisionOperationTest method testIntDivideByFloat.
@Test(description = "Test integer division by float")
public void testIntDivideByFloat() {
int a = Integer.MAX_VALUE;
double b = 1.23456789d;
double expectedResult = a / b;
BValue[] args = { new BInteger(a), new BFloat(b) };
BValue[] returns = BRunUtil.invoke(result, "intDivideByFloat", args);
Assert.assertEquals(returns.length, 1);
Assert.assertSame(returns[0].getClass(), BFloat.class, "Return type of the division is invalid");
double actualResult = ((BFloat) returns[0]).floatValue();
Assert.assertEquals(actualResult, expectedResult, DELTA, "Result of the division operation is incorrect");
}
Aggregations