Search in sources :

Example 16 with BInteger

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

the class CachingTest method testCacheEviction1.

@Test
public void testCacheEviction1() {
    String cacheName = "userCache";
    int expiryTime = 20000;
    int capacity = 10;
    float evictionFactor = 0.2f;
    BValue[] args = new BValue[4];
    args[0] = new BString(cacheName);
    args[1] = new BInteger(expiryTime);
    args[2] = new BInteger(capacity);
    args[3] = new BFloat(evictionFactor);
    BValue[] returns = BRunUtil.invoke(compileResult, "testCacheEviction1", args);
    Assert.assertTrue(returns.length == 2);
    Assert.assertTrue(returns[0] instanceof BStringArray);
    Assert.assertEquals(((BStringArray) returns[0]).get(0), "C");
    Assert.assertEquals(((BStringArray) returns[0]).get(1), "D");
    Assert.assertEquals(((BStringArray) returns[0]).get(2), "E");
    Assert.assertEquals(((BStringArray) returns[0]).get(3), "F");
    Assert.assertEquals(((BStringArray) returns[0]).get(4), "G");
    Assert.assertEquals(((BStringArray) returns[0]).get(5), "H");
    Assert.assertEquals(((BStringArray) returns[0]).get(6), "I");
    Assert.assertEquals(((BStringArray) returns[0]).get(7), "J");
    Assert.assertEquals(((BStringArray) returns[0]).get(8), "K");
    Assert.assertEquals(((BInteger) returns[1]).intValue(), 9);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BString(org.ballerinalang.model.values.BString) BStringArray(org.ballerinalang.model.values.BStringArray) Test(org.testng.annotations.Test)

Example 17 with BInteger

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

the class CachingTest method testCacheEviction4.

@Test
public void testCacheEviction4() {
    String cacheName = "userCache";
    int expiryTime = 20000;
    int capacity = 5;
    float evictionFactor = 0.2f;
    BValue[] args = new BValue[4];
    args[0] = new BString(cacheName);
    args[1] = new BInteger(expiryTime);
    args[2] = new BInteger(capacity);
    args[3] = new BFloat(evictionFactor);
    BValue[] returns = BRunUtil.invoke(compileResult, "testCacheEviction4", args);
    Assert.assertTrue(returns.length == 2);
    Assert.assertTrue(returns[0] instanceof BStringArray);
    Assert.assertEquals(((BStringArray) returns[0]).get(0), "A");
    Assert.assertEquals(((BStringArray) returns[0]).get(1), "B");
    Assert.assertEquals(((BStringArray) returns[0]).get(2), "C");
    Assert.assertEquals(((BStringArray) returns[0]).get(3), "D");
    Assert.assertEquals(((BStringArray) returns[0]).get(4), "F");
    Assert.assertEquals(((BInteger) returns[1]).intValue(), 5);
}
Also used : BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) BInteger(org.ballerinalang.model.values.BInteger) BFloat(org.ballerinalang.model.values.BFloat) BString(org.ballerinalang.model.values.BString) BStringArray(org.ballerinalang.model.values.BStringArray) Test(org.testng.annotations.Test)

Example 18 with BInteger

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

the class VectorNegativeTest method testRemoveIndexOutOfRange.

@Test(description = "Test case for testing removal of elements from outside of the bounds of a vector.")
public void testRemoveIndexOutOfRange() {
    long vectorSize = 10;
    long[] indices = new long[] { 0, vectorSize - 1, -1 };
    long[] expectedFinalValues = new long[] { 20, 30, 40, 50, 60, 70, 80, 90, 100 };
    String[] expectedErrMsgs = new String[] { "Index out of range: 9", "Index out of range: -1" };
    BValue[] returns = BRunUtil.invoke(compileResult, "testRemoveIndexOutOfRange", new BValue[] { buildIntArray(indices), new BInteger(vectorSize) });
    Assert.assertNotNull(returns);
    BStruct vector = (BStruct) returns[0];
    BRefValueArray vectorEntries = (BRefValueArray) vector.getRefField(0);
    long finalVectorSize = vector.getIntField(0);
    Assert.assertEquals(finalVectorSize, expectedFinalValues.length);
    for (int i = 0; i < finalVectorSize; i++) {
        Assert.assertEquals(vectorEntries.get(i).value(), expectedFinalValues[i]);
    }
    BRefValueArray removedVals = (BRefValueArray) returns[1];
    // only 1 valid index
    Assert.assertEquals(removedVals.size(), 1);
    Assert.assertEquals(((BInteger) removedVals.get(0)).intValue(), 10);
    BRefValueArray errors = (BRefValueArray) returns[2];
    Assert.assertEquals(errors.size(), expectedErrMsgs.length);
    for (int i = 0; i < expectedErrMsgs.length; i++) {
        Assert.assertTrue(errors.get(i).stringValue().contains(expectedErrMsgs[i]));
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 19 with BInteger

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

the class VectorNegativeTest method testGetIndexOutOfRange.

@Test(description = "Test case for testing retrieval of elements from outside the bounds of a vector.")
public void testGetIndexOutOfRange() {
    long[] expectedVals = new long[] { 10, 30 };
    long vectorSize = 10;
    long[] indices = new long[] { 0, 2, vectorSize, -1 };
    String[] expectedErrMsgs = new String[] { "Index out of range: 10", "Index out of range: -1" };
    BValue[] returns = BRunUtil.invoke(compileResult, "testGetIndexOutOfRange", new BValue[] { buildIntArray(indices), new BInteger(vectorSize) });
    Assert.assertNotNull(returns);
    BRefValueArray returnedVals = (BRefValueArray) returns[0];
    Assert.assertEquals(returnedVals.size(), expectedVals.length);
    for (int i = 0; i < expectedVals.length; i++) {
        Assert.assertEquals(((BInteger) returnedVals.get(i)).intValue(), expectedVals[i]);
    }
    BRefValueArray errors = (BRefValueArray) returns[1];
    Assert.assertEquals(errors.size(), expectedErrMsgs.length);
    for (int i = 0; i < expectedErrMsgs.length; i++) {
        Assert.assertTrue(errors.get(i).stringValue().contains(expectedErrMsgs[i]));
    }
}
Also used : BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

Example 20 with BInteger

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

the class VectorNegativeTest method testReplaceIndexOutOfRange.

@Test(description = "Test case for testing replacement of elements outside the bounds of a vector.")
public void testReplaceIndexOutOfRange() {
    long[] values = new long[] { 100, 110, 120 };
    // 1 valid index and 2 invalid indices
    long[] indices = new long[] { 3, 10, -1 };
    int vectorSize = 10;
    long[] expectedFinalValues = new long[] { 10, 20, 30, 100, 50, 60, 70, 80, 90, 100 };
    String[] expectedErrMsgs = new String[] { "Index out of range: 10", "Index out of range: -1" };
    BValue[] returns = BRunUtil.invoke(compileResult, "testReplaceIndexOutOfRange", new BValue[] { buildIntArray(values), buildIntArray(indices), new BInteger(vectorSize) });
    Assert.assertNotNull(returns);
    BStruct vector = (BStruct) returns[0];
    BRefValueArray vectorEntries = (BRefValueArray) vector.getRefField(0);
    long finalVectorSize = vector.getIntField(0);
    Assert.assertEquals(finalVectorSize, vectorSize);
    for (int i = 0; i < expectedFinalValues.length; i++) {
        Assert.assertEquals(vectorEntries.get(i).value(), expectedFinalValues[i]);
    }
    BRefValueArray errors = (BRefValueArray) returns[1];
    // Since there are 3 insertions
    Assert.assertEquals(errors.size(), 3);
    // Since first insertion is valid, the error is null
    Assert.assertNull(errors.get(0).value());
    Assert.assertTrue(errors.get(1).stringValue().contains(expectedErrMsgs[0]));
    Assert.assertTrue(errors.get(2).stringValue().contains(expectedErrMsgs[1]));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) BValue(org.ballerinalang.model.values.BValue) BInteger(org.ballerinalang.model.values.BInteger) BRefValueArray(org.ballerinalang.model.values.BRefValueArray) BeforeTest(org.testng.annotations.BeforeTest) Test(org.testng.annotations.Test)

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