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);
}
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);
}
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");
}
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.");
}
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);
}
Aggregations