Search in sources :

Example 36 with BFloat

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

the class DivisionOperationTest method testFloatDivisionInt.

@Test
public void testFloatDivisionInt() {
    BValue[] args = { new BFloat(110f), new BInteger(22) };
    BValue[] returns = BRunUtil.invoke(result, "floatDivideByInt", args);
    Assert.assertTrue(returns[0] instanceof BFloat);
    final String expected = "5.0";
    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) Test(org.testng.annotations.Test)

Example 37 with BFloat

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

the class GreaterLessThanOperationTest method testFloatRangeExpr.

@Test(description = "Test float greater than, less than expression")
public void testFloatRangeExpr() {
    BValue[] args = { new BFloat(-123.8f) };
    BValue[] returns = BRunUtil.invoke(result, "testFloatRanges", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BInteger.class);
    long actual = ((BInteger) returns[0]).intValue();
    long expected = 1;
    Assert.assertEquals(actual, expected);
    args = new BValue[] { new BFloat(75.4f) };
    returns = BRunUtil.invoke(result, "testFloatRanges", args);
    actual = ((BInteger) returns[0]).intValue();
    expected = 2;
    Assert.assertEquals(actual, expected);
    args = new BValue[] { new BFloat(321.45f) };
    returns = BRunUtil.invoke(result, "testFloatRanges", args);
    actual = ((BInteger) returns[0]).intValue();
    expected = 3;
    Assert.assertEquals(actual, expected);
}
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 38 with BFloat

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

the class GreaterLessThanOperationTest method testIntGTFloat.

@Test
public void testIntGTFloat() {
    BValue[] args = { new BInteger(110), new BFloat(22L) };
    BValue[] returns = BRunUtil.invoke(result, "intGTFloat", args);
    Assert.assertTrue(returns[0] instanceof BBoolean);
    final String expected = "true";
    Assert.assertEquals(returns[0].stringValue(), expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BBoolean(org.ballerinalang.model.values.BBoolean) Test(org.testng.annotations.Test)

Example 39 with BFloat

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

the class ModOperationTest method intFloatMod.

private void intFloatMod(int val1, float val2, double expected) {
    BValue[] args = { new BInteger(val1), new BFloat(val2) };
    BValue[] returns = BRunUtil.invoke(result, "intFloatMod", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    double actual = ((BFloat) returns[0]).floatValue();
    Assert.assertEquals(actual, expected);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat)

Example 40 with BFloat

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

the class MultiplyOperationTest method testFloatMultiplyExpr.

@Test(description = "Test two float multiply expression")
public void testFloatMultiplyExpr() {
    BValue[] args = { new BFloat(40.0f), new BFloat(40.0f) };
    BValue[] returns = BRunUtil.invoke(result, "floatMultiply", args);
    Assert.assertEquals(returns.length, 1);
    Assert.assertSame(returns[0].getClass(), BFloat.class);
    double actual = ((BFloat) returns[0]).floatValue();
    double expected = 1600.0f;
    Assert.assertEquals(actual, expected);
}
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