Search in sources :

Example 91 with BInteger

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);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 92 with BInteger

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.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 93 with BInteger

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);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 94 with BInteger

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);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 95 with BInteger

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");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Aggregations

BInteger (org.ballerinalang.model.values.BInteger)364 BValue (org.ballerinalang.model.values.BValue)324 Test (org.testng.annotations.Test)305 BString (org.ballerinalang.model.values.BString)91 BFloat (org.ballerinalang.model.values.BFloat)55 BStruct (org.ballerinalang.model.values.BStruct)33 BBoolean (org.ballerinalang.model.values.BBoolean)24 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)18 CompileResult (org.ballerinalang.launcher.util.CompileResult)12 BBlob (org.ballerinalang.model.values.BBlob)11 BeforeTest (org.testng.annotations.BeforeTest)11 BIntArray (org.ballerinalang.model.values.BIntArray)9 BMap (org.ballerinalang.model.values.BMap)9 BRefType (org.ballerinalang.model.values.BRefType)8 BStringArray (org.ballerinalang.model.values.BStringArray)8 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)8 BType (org.ballerinalang.model.types.BType)6 BStructType (org.ballerinalang.model.types.BStructType)4 BJSON (org.ballerinalang.model.values.BJSON)4 UnsupportedFieldTypeException (org.ballerinalang.net.grpc.exception.UnsupportedFieldTypeException)4