Search in sources :

Example 11 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class TestOptionalArgsInNativeFunc method execute.

@Override
public void execute(Context ctx) {
    long a;
    double b;
    String c;
    long d;
    String e;
    BIntArray z;
    try {
        a = ctx.getIntArgument(0);
        b = ctx.getFloatArgument(0);
        c = ctx.getStringArgument(0);
        d = ctx.getIntArgument(1);
        e = ctx.getStringArgument(1);
        z = (BIntArray) ctx.getRefArgument(0);
    } catch (Throwable t) {
        throw new BallerinaException("Mocked function failed: " + t.getMessage());
    }
    // Setting output value.
    ctx.setReturnValues(new BInteger(a), new BFloat(b), new BString(c), new BInteger(d), new BString(e), z);
}
Also used : BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BString(org.ballerinalang.model.values.BString) BallerinaException(org.ballerinalang.util.exceptions.BallerinaException) BIntArray(org.ballerinalang.model.values.BIntArray)

Example 12 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class ForkJoinInFunctionTest method testForkJoinAll.

@Test(description = "Test Fork Join All")
public void testForkJoinAll() {
    CompileResult result = BCompileUtil.compile("test-src/workers/fork-join-in-all.bal");
    BValue[] args = {};
    BValue[] returns = BRunUtil.invoke(result, "testForkJoinAll", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertTrue(returns[0] instanceof BIntArray);
    Assert.assertEquals(((BIntArray) returns[0]).size(), 2);
    Assert.assertEquals(((BIntArray) returns[0]).get(0), 234);
    Assert.assertEquals(((BIntArray) returns[0]).get(1), 500);
}
Also used : BValue(org.ballerinalang.model.values.BValue) CompileResult(org.ballerinalang.launcher.util.CompileResult) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 13 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class ArrayTest method testIntArrayLength.

@Test
public void testIntArrayLength() {
    BIntArray arrayValue = new BIntArray();
    arrayValue.add(0, 10);
    arrayValue.add(1, 11);
    arrayValue.add(2, 12);
    BValue[] args = { arrayValue };
    BValue[] returnVals = BRunUtil.invoke(compileResult, "testIntArrayLength", args);
    Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null || returnVals[1] == null, "Invalid Return Values.");
    Assert.assertEquals(((BInteger) returnVals[0]).intValue(), 3, "Length didn't match");
    Assert.assertEquals(((BInteger) returnVals[1]).intValue(), 4, "Length didn't match");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 14 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class BArrayValueTest method addValueToIntegerArray.

@Test(description = "Test add value operation on int arrays")
public void addValueToIntegerArray() {
    BValue[] returns = BRunUtil.invoke(compileResult, "addValueToIntArray");
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BIntArray.class);
    BIntArray arrayValue = (BIntArray) returns[0];
    Assert.assertEquals(arrayValue.size(), 200, "Invalid arrays size.");
    Assert.assertEquals(arrayValue.get(0), (-10), "Invalid value returned.");
    Assert.assertEquals(arrayValue.get(15), 20, "Invalid value returned.");
    Assert.assertEquals(arrayValue.get(99), 2147483647, "Invalid value returned.");
    Assert.assertEquals(arrayValue.get(100), -4, "Invalid value returned.");
    Assert.assertEquals(arrayValue.get(115), -2147483647, "Invalid value returned.");
    Assert.assertEquals(arrayValue.get(199), 6, "Invalid value returned.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Example 15 with BIntArray

use of org.ballerinalang.model.values.BIntArray in project ballerina by ballerina-lang.

the class AssignStmtTest method invokeAssignmentTest.

@Test
public void invokeAssignmentTest() {
    BValue[] args = { new BInteger(100) };
    BValue[] returns = BRunUtil.invoke(result, "testIntAssignStmt", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    long actual = ((BInteger) returns[0]).intValue();
    long expected = 100;
    Assert.assertEquals(actual, expected);
    // floattype assignment test
    args = new BValue[] { new BFloat(2.3f) };
    returns = BRunUtil.invoke(result, "testFloatAssignStmt", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    double actualFloat = ((BFloat) returns[0]).floatValue();
    double expectedFloat = 2.3f;
    Assert.assertEquals(actualFloat, expectedFloat);
    // Boolean assignment test
    args = new BValue[] { new BBoolean(true) };
    returns = BRunUtil.invoke(result, "testBooleanAssignStmt", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BBoolean.class);
    boolean actualBoolean = ((BBoolean) returns[0]).booleanValue();
    Assert.assertEquals(actualBoolean, true);
    // String assignment test
    args = new BValue[] { new BString("Test Value") };
    returns = BRunUtil.invoke(result, "testStringAssignStmt", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BString.class);
    String actualString = returns[0].stringValue();
    String expectedString = "Test Value";
    Assert.assertEquals(actualString, expectedString);
    // Array index to int assignment test
    BIntArray arrayValue = new BIntArray();
    arrayValue.add(0, 150);
    args = new BValue[] { arrayValue };
    returns = BRunUtil.invoke(result, "testArrayIndexToIntAssignStmt", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    actual = ((BInteger) returns[0]).intValue();
    expected = 150;
    Assert.assertEquals(actual, expected);
    // Int to array index assignment test
    args = new BValue[] { new BInteger(250) };
    returns = BRunUtil.invoke(result, "testIntToArrayAssignStmt", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    actual = ((BInteger) returns[0]).intValue();
    expected = 250;
    Assert.assertEquals(actual, expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BBoolean(org.ballerinalang.model.values.BBoolean) BString(org.ballerinalang.model.values.BString) BIntArray(org.ballerinalang.model.values.BIntArray) Test(org.testng.annotations.Test)

Aggregations

BIntArray (org.ballerinalang.model.values.BIntArray)33 BValue (org.ballerinalang.model.values.BValue)25 Test (org.testng.annotations.Test)25 BString (org.ballerinalang.model.values.BString)14 BInteger (org.ballerinalang.model.values.BInteger)9 BStruct (org.ballerinalang.model.values.BStruct)9 BFloatArray (org.ballerinalang.model.values.BFloatArray)8 BStringArray (org.ballerinalang.model.values.BStringArray)8 BBooleanArray (org.ballerinalang.model.values.BBooleanArray)7 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)7 BJSON (org.ballerinalang.model.values.BJSON)6 BMap (org.ballerinalang.model.values.BMap)6 BBlobArray (org.ballerinalang.model.values.BBlobArray)4 BFloat (org.ballerinalang.model.values.BFloat)4 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)4 BRefType (org.ballerinalang.model.values.BRefType)3 CompileResult (org.ballerinalang.launcher.util.CompileResult)2 BMapType (org.ballerinalang.model.types.BMapType)2 BBoolean (org.ballerinalang.model.values.BBoolean)2 StructureType (org.ballerinalang.model.values.StructureType)2