Search in sources :

Example 31 with BFloat

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

the class ValueTypeCastExprTest method testFloatToBoolean.

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

Example 32 with BFloat

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

the class UnaryExprTest method floatUnaryExprTest.

@Test(description = "Test float unary negative expression")
public void floatUnaryExprTest() {
    BValue[] args = {};
    BValue[] returns = BRunUtil.invoke(result, "negativeFloatTest", args);
    Assert.assertEquals(returns.length, 2);
    BFloat x = (BFloat) returns[0];
    Assert.assertSame(x.getClass(), BFloat.class, "Invalid class type returned.");
    Assert.assertEquals(x.floatValue(), -5.0D, "Invalid value returned.");
    BFloat y = (BFloat) returns[1];
    Assert.assertSame(y.getClass(), BFloat.class, "Invalid class type returned.");
    Assert.assertEquals(y.floatValue(), 5.0D, "Invalid value returned.");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 33 with BFloat

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

the class DivisionOperationTest method testFloatDivideByInt.

@Test(description = "Test float number division by integer")
public void testFloatDivideByInt() {
    double a = Float.MAX_VALUE;
    int b = 123456789;
    double expectedResult = a / b;
    BValue[] args = { new BFloat(a), new BInteger(b) };
    BValue[] returns = BRunUtil.invoke(result, "floatDivideByInt", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class, "Return type of the division is invalid");
    double actualResult = ((BFloat) returns[0]).floatValue();
    Assert.assertEquals(actualResult, expectedResult, DELTA, "Result of the division operation is incorrect");
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) BInteger(org.ballerinalang.model.values.BInteger) Test(org.testng.annotations.Test)

Example 34 with BFloat

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

the class DivisionOperationTest method testFloatDivideExpr.

@Test(description = "Test two float divide expression")
public void testFloatDivideExpr() {
    float a = 8.5f;
    float b = 4.1f;
    double expectedResult = a / b;
    BValue[] args = { new BFloat(a), new BFloat(b) };
    BValue[] returns = BRunUtil.invoke(result, "floatDivide", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    double actual = ((BFloat) returns[0]).floatValue();
    Assert.assertEquals(actual, expectedResult, DELTA);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BFloat(org.ballerinalang.model.values.BFloat) Test(org.testng.annotations.Test)

Example 35 with BFloat

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

the class DivisionOperationTest method testIntDivideByFloat.

@Test(description = "Test integer division by float")
public void testIntDivideByFloat() {
    int a = Integer.MAX_VALUE;
    double b = 1.23456789d;
    double expectedResult = a / b;
    BValue[] args = { new BInteger(a), new BFloat(b) };
    BValue[] returns = BRunUtil.invoke(result, "intDivideByFloat", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class, "Return type of the division is invalid");
    double actualResult = ((BFloat) returns[0]).floatValue();
    Assert.assertEquals(actualResult, expectedResult, DELTA, "Result of the division operation is incorrect");
}
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)

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