Search in sources :

Example 26 with BFloat

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

the class TypeCastExprTest method testFloatToInt.

// @Test
// public void testXMLToJSON() {
// BValue[] args = {new BXML("<name>chanaka</name>")};
// BValue[] returns = Functions.invoke(bLangProgram, "xmltojson", args);
// Assert.assertTrue(returns[0] instanceof BJSON);
// final String expected = "{\"name\":\"chanaka\"}";
// Assert.assertEquals(returns[0].stringValue(), expected);
// }
// 
// @Test
// public void testJSONToXML() {
// BValue[] args = {new BJSON("{\"name\":\"chanaka\"}")};
// BValue[] returns = BTestUtils.invoke(result, "jsontoxml", args);
// Assert.assertTrue(returns[0] instanceof BXML);
// final String expected = "<name>chanaka</name>";
// Assert.assertEquals(returns[0].stringValue(), expected);
// }
@Test
public void testFloatToInt() {
    BValue[] args = { new BFloat(222222.44444f) };
    BValue[] returns = BRunUtil.invoke(result, "floattoint", args);
    Assert.assertTrue(returns[0] instanceof BInteger);
    final String expected = "222222";
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) BInteger(org.ballerinalang.model.values.BInteger) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 27 with BFloat

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

the class TypeCastExprTest method testIntToFloat.

@Test
public void testIntToFloat() {
    BValue[] args = { new BInteger(55555555) };
    BValue[] returns = BRunUtil.invoke(result, "inttofloat", args);
    Assert.assertTrue(returns[0] instanceof BFloat);
    double expected = 5.5555555E7;
    Assert.assertEquals(((BFloat) returns[0]).floatValue(), expected, DELTA);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 28 with BFloat

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

the class ValueTypeCastExprTest method testFloatToAny.

@Test
public void testFloatToAny() {
    BValue[] args = { new BFloat(111.333f) };
    BValue[] returns = BRunUtil.invoke(result, "floatToAny", args);
    Assert.assertTrue(returns[0] instanceof BFloat);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 29 with BFloat

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

the class ValueTypeCastExprTest method testBooleanToFloat.

@Test
public void testBooleanToFloat() {
    BValue[] args = { new BBoolean(true) };
    BValue[] returns = BRunUtil.invoke(result, "booleanToFloat", args);
    Assert.assertTrue(returns[0] instanceof BFloat);
    final double expected = 1.0;
    Assert.assertEquals(((BFloat) returns[0]).floatValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BBoolean(org.ballerinalang.model.values.BBoolean) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 30 with BFloat

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

the class ValueTypeCastExprTest method testFloatToInt.

@Test
public void testFloatToInt() {
    BValue[] args = { new BFloat(222222.44444f) };
    BValue[] returns = BRunUtil.invoke(result, "floatToInt", args);
    Assert.assertTrue(returns[0] instanceof BInteger);
    final String expected = "222222";
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) BInteger(org.ballerinalang.model.values.BInteger) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Aggregations

BFloat (org.ballerinalang.model.values.BFloat)158 BValue (org.ballerinalang.model.values.BValue)119 Test (org.testng.annotations.Test)107 BInteger (org.ballerinalang.model.values.BInteger)55 BString (org.ballerinalang.model.values.BString)41 BBoolean (org.ballerinalang.model.values.BBoolean)21 BRefType (org.ballerinalang.model.values.BRefType)7 BStruct (org.ballerinalang.model.values.BStruct)7 BType (org.ballerinalang.model.types.BType)6 BBlob (org.ballerinalang.model.values.BBlob)6 BStringArray (org.ballerinalang.model.values.BStringArray)5 BStructType (org.ballerinalang.model.types.BStructType)4 BIntArray (org.ballerinalang.model.values.BIntArray)4 UnsupportedFieldTypeException (org.ballerinalang.net.grpc.exception.UnsupportedFieldTypeException)4 BallerinaException (org.ballerinalang.util.exceptions.BallerinaException)4 BJSON (org.ballerinalang.model.values.BJSON)3 CompileResult (org.ballerinalang.launcher.util.CompileResult)2 BMap (org.ballerinalang.model.values.BMap)2 BRefValueArray (org.ballerinalang.model.values.BRefValueArray)2 Message (org.ballerinalang.net.grpc.Message)2