Search in sources :

Example 86 with BFloat

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

the class AssertTest method testAssertFloatEquals.

@Test
public void testAssertFloatEquals() {
    BValue[] args = { new BFloat(10.000), new BFloat(20.050) };
    BTestUtils.invoke(compileResult, "testAssertFloatEquals", args);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 87 with BFloat

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

the class VariableDefinitionTest method testUpdateVarValue.

@Test
public void testUpdateVarValue() {
    int v1 = 56;
    boolean v3 = false;
    String v4 = "newstr";
    double v5 = 68.3325f;
    BValue[] args = { new BInteger(v1), new BBoolean(v3), new BString(v4), new BFloat(v5) };
    BValue[] returns = BRunUtil.invoke(result, "updateVarValue", args);
    Assert.assertEquals(returns.length, 4);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    long i = ((BInteger) returns[0]).intValue();
    Assert.assertEquals(i, v1);
    Assert.assertSame(returns[1].getClass(), BBoolean.class);
    boolean b = ((BBoolean) returns[1]).booleanValue();
    Assert.assertEquals(b, v3);
    Assert.assertSame(returns[2].getClass(), BString.class);
    String s = ((BString) returns[2]).stringValue();
    Assert.assertEquals(s, v4);
    Assert.assertSame(returns[3].getClass(), BFloat.class);
    double f = ((BFloat) returns[3]).floatValue();
    Assert.assertEquals(f, v5, DELTA);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BBoolean(org.ballerinalang.model.values.BBoolean) BFloat(org.ballerinalang.model.values.BFloat) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 88 with BFloat

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

the class VariableDefinitionTest method testInlineVarInit.

@Test
public void testInlineVarInit() {
    BValue[] returns = BRunUtil.invoke(result, "inlineVarInit", new BValue[0]);
    Assert.assertEquals(returns.length, 4);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    long i = ((BInteger) returns[0]).intValue();
    Assert.assertEquals(i, 10);
    Assert.assertSame(returns[1].getClass(), BBoolean.class);
    boolean b = ((BBoolean) returns[1]).booleanValue();
    Assert.assertEquals(b, true);
    Assert.assertSame(returns[2].getClass(), BString.class);
    String s = ((BString) returns[2]).stringValue();
    Assert.assertEquals(s, "hello");
    Assert.assertSame(returns[3].getClass(), BFloat.class);
    double f = ((BFloat) returns[3]).floatValue();
    Assert.assertEquals(f, 2.6f, DELTA);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BBoolean(org.ballerinalang.model.values.BBoolean) BFloat(org.ballerinalang.model.values.BFloat) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 89 with BFloat

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

the class BFloatValueTest method testNegativeFloatValue.

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

Example 90 with BFloat

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

the class BFloatValueTest method testFloatValueMultiplication.

@Test(description = "Test double value Multiplication")
public void testFloatValueMultiplication() {
    BValue[] returns = BRunUtil.invoke(result, "testFloatMultiplication", new BValue[] {});
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    BFloat floatValue = (BFloat) returns[0];
    Assert.assertEquals(floatValue.floatValue(), 13.75d, "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