use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.
the class TableIterator method getDataArray.
protected BNewArray getDataArray(Array array) throws SQLException {
Object[] dataArray = generateArrayDataResult(array);
if (dataArray == null || dataArray.length == 0) {
return null;
}
Object obj = dataArray[0];
int length = dataArray.length;
if (obj instanceof String) {
BStringArray stringDataArray = new BStringArray();
for (int i = 0; i < length; i++) {
stringDataArray.add(i, (String) dataArray[i]);
}
return stringDataArray;
} else if (obj instanceof Boolean) {
BBooleanArray boolDataArray = new BBooleanArray();
for (int i = 0; i < length; i++) {
boolDataArray.add(i, ((Boolean) dataArray[i]) ? 1 : 0);
}
return boolDataArray;
} else if (obj instanceof Integer) {
BIntArray intDataArray = new BIntArray();
for (int i = 0; i < length; i++) {
intDataArray.add(i, ((Integer) dataArray[i]));
}
return intDataArray;
} else if (obj instanceof Long) {
BIntArray longDataArray = new BIntArray();
for (int i = 0; i < length; i++) {
longDataArray.add(i, (Long) dataArray[i]);
}
return longDataArray;
} else if (obj instanceof Float) {
BFloatArray floatDataArray = new BFloatArray();
for (int i = 0; i < length; i++) {
floatDataArray.add(i, (Float) dataArray[i]);
}
return floatDataArray;
} else if (obj instanceof Double) {
BFloatArray doubleDataArray = new BFloatArray();
for (int i = 0; i < dataArray.length; i++) {
doubleDataArray.add(i, (Double) dataArray[i]);
}
return doubleDataArray;
} else {
return null;
}
}
use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.
the class TableTest method testArrayData.
@Test(groups = "TableTest", description = "Check array data types.")
public void testArrayData() {
BValue[] returns = BRunUtil.invoke(result, "testArrayData");
Assert.assertEquals(returns.length, 5);
Assert.assertTrue(returns[0] instanceof BIntArray);
BIntArray intArray = (BIntArray) returns[0];
Assert.assertEquals(intArray.get(0), 1);
Assert.assertEquals(intArray.get(1), 2);
Assert.assertEquals(intArray.get(2), 3);
Assert.assertTrue(returns[1] instanceof BIntArray);
BIntArray longArray = (BIntArray) returns[1];
Assert.assertEquals(longArray.get(0), 100000000);
Assert.assertEquals(longArray.get(1), 200000000);
Assert.assertEquals(longArray.get(2), 300000000);
Assert.assertTrue(returns[2] instanceof BFloatArray);
BFloatArray doubleArray = (BFloatArray) returns[2];
Assert.assertEquals(doubleArray.get(0), 245.23);
Assert.assertEquals(doubleArray.get(1), 5559.49);
Assert.assertEquals(doubleArray.get(2), 8796.123);
Assert.assertTrue(returns[3] instanceof BStringArray);
BStringArray stringArray = (BStringArray) returns[3];
Assert.assertEquals(stringArray.get(0), "Hello");
Assert.assertEquals(stringArray.get(1), "Ballerina");
Assert.assertTrue(returns[4] instanceof BBooleanArray);
BBooleanArray booleanArray = (BBooleanArray) returns[4];
Assert.assertEquals(booleanArray.get(0), 1);
Assert.assertEquals(booleanArray.get(1), 0);
Assert.assertEquals(booleanArray.get(2), 1);
}
use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.
the class TypeCastExprTest method testIntArrayToLongArray.
@Test
public void testIntArrayToLongArray() {
BValue[] returns = BRunUtil.invoke(result, "intarrtofloatarr");
Assert.assertTrue(returns[0] instanceof BFloatArray);
BFloatArray result = (BFloatArray) returns[0];
Assert.assertEquals(result.get(0), 999.0, DELTA);
Assert.assertEquals(result.get(1), 95.0, DELTA);
Assert.assertEquals(result.get(2), 889.0, DELTA);
}
use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.
the class ValueTypeCastExprTest method testIntArrayToLongArray.
@Test
public void testIntArrayToLongArray() {
BValue[] returns = BRunUtil.invoke(result, "intarrtofloatarr", new BValue[] {});
Assert.assertTrue(returns[0] instanceof BFloatArray);
BFloatArray result = (BFloatArray) returns[0];
Assert.assertEquals(result.get(0), 999.0, DELTA);
Assert.assertEquals(result.get(1), 95.0, DELTA);
Assert.assertEquals(result.get(2), 889.0, DELTA);
}
use of org.ballerinalang.model.values.BFloatArray in project ballerina by ballerina-lang.
the class ArrayInitializerExprTest method testFloatArrayInitWithIntExpr.
@Test(description = "Test float array initialization with integer values")
public void testFloatArrayInitWithIntExpr() {
BValue[] args = {};
BValue[] returns = BRunUtil.invoke(compileResult, "floatArrayInitWithInt", args);
Assert.assertEquals(returns.length, 1);
Assert.assertSame(returns[0].getClass(), BFloatArray.class);
BFloatArray arrayValue = (BFloatArray) returns[0];
Assert.assertEquals(arrayValue.size(), 3);
Assert.assertEquals(arrayValue.get(0), 2.0);
Assert.assertEquals(arrayValue.get(1), 4.0);
Assert.assertEquals(arrayValue.get(2), 5.0);
}
Aggregations