Search in sources :

Example 96 with BInteger

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

Example 97 with BInteger

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

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

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

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

the class ModOperationTest method intMod.

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

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