Search in sources :

Example 1 with BFloat

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

the class StringTest method testFloatValueOf.

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

Example 2 with BFloat

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

the class BAnyTypeSuccessScenariosTest method assignmentTest.

@Test(description = "Test any variable assignment with float")
public void assignmentTest() {
    BValue[] returns = BRunUtil.invoke(result, "assignmentTest", new BValue[0]);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    BFloat floatVal = (BFloat) returns[0];
    Assert.assertEquals(floatVal.floatValue(), 44.3d, "Invalid float value returned.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 3 with BFloat

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

the class BFloatValueTest method testFloatValueAssignmentByReturnValue.

@Test(description = "Test double value assignment from a value returned by function")
public void testFloatValueAssignmentByReturnValue() {
    BValue[] returns = BRunUtil.invoke(result, "testFloatValueAssignmentByReturnValue", new BValue[] {});
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    BFloat floatValue = (BFloat) returns[0];
    Assert.assertEquals(floatValue.floatValue(), 10.1d, "Invalid float value returned.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 4 with BFloat

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

the class BFloatValueTest method testFloatValueDivision.

@Test(description = "Test double value Division")
public void testFloatValueDivision() {
    BValue[] returns = BRunUtil.invoke(result, "testFloatDivision", new BValue[] {});
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    BFloat floatValue = (BFloat) returns[0];
    Assert.assertEquals(floatValue.floatValue(), 5.0d, "Invalid float value returned.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 5 with BFloat

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

the class BFloatValueTest method testFloatValueSubtraction.

@Test(description = "Test double value Subtraction")
public void testFloatValueSubtraction() {
    BValue[] returns = BRunUtil.invoke(result, "testFloatSubtraction", new BValue[] {});
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    BFloat floatValue = (BFloat) returns[0];
    Assert.assertEquals(floatValue.floatValue(), 10.0d, "Invalid float value returned.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) 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