Search in sources :

Example 76 with BInteger

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

the class TypeCastExprTest method testIntToString.

/*@Test
    public void testStringToXML() {
        BValue[] args = {new BString("<name>chanaka</name>")};
        BValue[] returns = BTestUtils.invoke(result, "stringtoxml", args);
        Assert.assertTrue(returns[0] instanceof BXML);
        final String expected = "<name>chanaka</name>";
        Assert.assertEquals(returns[0].stringValue(), expected);
    }*/
@Test
public void testIntToString() {
    BValue[] args = { new BInteger(111) };
    BValue[] returns = BRunUtil.invoke(result, "inttostring", args);
    Assert.assertTrue(returns[0] instanceof BString);
    final String expected = "111";
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 77 with BInteger

use of org.ballerinalang.model.values.BInteger 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 78 with BInteger

use of org.ballerinalang.model.values.BInteger 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 79 with BInteger

use of org.ballerinalang.model.values.BInteger 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)

Example 80 with BInteger

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

the class ValueTypeCastExprTest method testBooleanToInt.

@Test
public void testBooleanToInt() {
    BValue[] args = { new BBoolean(true) };
    BValue[] returns = BRunUtil.invoke(result, "booleanToInt", args);
    Assert.assertTrue(returns[0] instanceof BInteger);
    final int expected = 1;
    Assert.assertEquals(((BInteger) returns[0]).intValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BBoolean(org.ballerinalang.model.values.BBoolean) 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