use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class LengthOfOperatorTest method testArrayLengthAccessExprArrayInitializationCase.
@Test(description = "Test lengthof unary expression when present in Array initialization statement.")
public void testArrayLengthAccessExprArrayInitializationCase() {
BValue[] args = { new BInteger(100), new BInteger(5) };
BValue[] returns = BRunUtil.invoke(result, "arrayLengthAccessTestArrayInitializerCase", args);
Assert.assertEquals(returns.length, 1);
Assert.assertSame(returns[0].getClass(), BInteger.class);
int actual = (int) ((BInteger) returns[0]).intValue();
int expected = 3;
Assert.assertEquals(actual, expected);
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class UnaryExprTest method integerUnaryExprTest.
@Test(description = "Test unary negative expression")
public void integerUnaryExprTest() {
BValue[] args = {};
BValue[] returns = BRunUtil.invoke(result, "negativeIntTest", args);
Assert.assertEquals(returns.length, 2);
BInteger x = (BInteger) returns[0];
Assert.assertSame(x.getClass(), BInteger.class, "Invalid class type returned.");
Assert.assertEquals(x.intValue(), (-5), "Invalid value returned.");
BInteger y = (BInteger) returns[1];
Assert.assertSame(y.getClass(), BInteger.class, "Invalid class type returned.");
Assert.assertEquals(y.intValue(), 5, "Invalid value returned.");
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class UnaryExprTest method unaryPositiveNegationTest.
@Test(description = "Test unary positive negation expression")
public void unaryPositiveNegationTest() {
long a = 3;
long expectedResult = +-a;
BValue[] args = { new BInteger(a) };
BValue[] returns = BRunUtil.invoke(result, "unaryPositiveNegationTest", args);
Assert.assertEquals(returns.length, 1);
Assert.assertSame(returns[0].getClass(), BInteger.class, "Invalid class type returned.");
long actualResult = ((BInteger) returns[0]).intValue();
Assert.assertEquals(actualResult, expectedResult);
}
use of org.ballerinalang.model.values.BInteger in project ballerina by ballerina-lang.
the class DivisionOperationTest method testIntDivideByZeroExpr.
@Test(description = "Test two int divide expression", expectedExceptions = BLangRuntimeException.class)
public void testIntDivideByZeroExpr() {
BValue[] args = { new BInteger(2000), new BInteger(0) };
BRunUtil.invoke(result, "intDivide", args);
}
use of org.ballerinalang.model.values.BInteger 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");
}
Aggregations