use of org.ballerinalang.model.values.BInteger 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");
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class DivisionOperationTest method testFloatDivisionInt.
@Test
public void testFloatDivisionInt() {
BValue[] args = { new BFloat(110f), new BInteger(22) };
BValue[] returns = BRunUtil.invoke(result, "floatDivideByInt", args);
Assert.assertTrue(returns[0] instanceof BFloat);
final String expected = "5.0";
Assert.assertEquals(returns[0].stringValue(), expected);
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class GreaterLessThanOperationTest method testFloatRangeExpr.
@Test(description = "Test float greater than, less than expression")
public void testFloatRangeExpr() {
BValue[] args = { new BFloat(-123.8f) };
BValue[] returns = BRunUtil.invoke(result, "testFloatRanges", args);
Assert.assertEquals(returns.length, 1);
Assert.assertSame(returns[0].getClass(), BInteger.class);
long actual = ((BInteger) returns[0]).intValue();
long expected = 1;
Assert.assertEquals(actual, expected);
args = new BValue[] { new BFloat(75.4f) };
returns = BRunUtil.invoke(result, "testFloatRanges", args);
actual = ((BInteger) returns[0]).intValue();
expected = 2;
Assert.assertEquals(actual, expected);
args = new BValue[] { new BFloat(321.45f) };
returns = BRunUtil.invoke(result, "testFloatRanges", args);
actual = ((BInteger) returns[0]).intValue();
expected = 3;
Assert.assertEquals(actual, expected);
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class GreaterLessThanOperationTest method testIntGTFloat.
@Test
public void testIntGTFloat() {
BValue[] args = { new BInteger(110), new BFloat(22L) };
BValue[] returns = BRunUtil.invoke(result, "intGTFloat", args);
Assert.assertTrue(returns[0] instanceof BBoolean);
final String expected = "true";
Assert.assertEquals(returns[0].stringValue(), expected);
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class ModOperationTest method intMod.
private void intMod(int val1, int val2, long expected) {
BValue[] args = { new BInteger(val1), new BInteger(val2) };
BValue[] returns = BRunUtil.invoke(result, "intMod", args);
Assert.assertEquals(returns.length, 1);
Assert.assertSame(returns[0].getClass(), BInteger.class);
long actual = ((BInteger) returns[0]).intValue();
Assert.assertEquals(actual, expected);
}
Aggregations