Search in sources :

Example 1 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class GraphKeyTypeTransformTest method testFromShortValue.

@Test
public void testFromShortValue() throws Exception {
    TranslateFunction<ShortValue, LongValueWithProperHashCode> translator = new UnsignedShortValueToLongValueWithProperHashCode();
    Assert.assertEquals(new LongValueWithProperHashCode(0L), translator.translate(new ShortValue((short) 0), longValueWithProperHashCode));
    Assert.assertEquals(new LongValueWithProperHashCode(Short.MAX_VALUE + 1), translator.translate(new ShortValue(Short.MIN_VALUE), longValueWithProperHashCode));
    Assert.assertEquals(new LongValueWithProperHashCode(LongValueToUnsignedShortValue.MAX_VERTEX_COUNT - 1), translator.translate(new ShortValue((short) -1), longValueWithProperHashCode));
}
Also used : UnsignedShortValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortValueToLongValueWithProperHashCode) LongValueToUnsignedShortValue(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToUnsignedShortValue) ShortValue(org.apache.flink.types.ShortValue) UnsignedShortValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortValueToLongValueWithProperHashCode) DoubleToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleToLongValueWithProperHashCode) UnsignedByteValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedByteValueToLongValueWithProperHashCode) UnsignedIntToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedIntToLongValueWithProperHashCode) DoubleValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleValueToLongValueWithProperHashCode) StringToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.StringToLongValueWithProperHashCode) UnsignedFloatToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedFloatToLongValueWithProperHashCode) LongValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToLongValueWithProperHashCode) StringValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.StringValueToLongValueWithProperHashCode) UnsignedByteToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedByteToLongValueWithProperHashCode) UnsignedFloatValueToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedFloatValueToLongValueWithProperHashCode) UnsignedShortToLongValueWithProperHashCode(org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortToLongValueWithProperHashCode) Test(org.junit.Test)

Example 2 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class ShortValueArrayTest method testUnboundedArray.

@Test
public void testUnboundedArray() {
    int count = 4096;
    ValueArray<ShortValue> lva = new ShortValueArray();
    // add several elements
    for (int i = 0; i < count; i++) {
        assertFalse(lva.isFull());
        assertEquals(i, lva.size());
        assertTrue(lva.add(new ShortValue((short) i)));
        assertEquals(i + 1, lva.size());
    }
    // array never fills
    assertFalse(lva.isFull());
    assertEquals(count, lva.size());
    // verify the array values
    int idx = 0;
    for (ShortValue lv : lva) {
        assertEquals((short) idx++, lv.getValue());
    }
    // add element past end of array
    assertTrue(lva.add(new ShortValue((short) count)));
    assertTrue(lva.addAll(lva));
    // test copy
    assertEquals(lva, lva.copy());
    // test copyTo
    ShortValueArray lvaTo = new ShortValueArray();
    lva.copyTo(lvaTo);
    assertEquals(lva, lvaTo);
    // test mark/reset
    int size = lva.size();
    lva.mark();
    assertTrue(lva.add(new ShortValue()));
    assertEquals(size + 1, lva.size());
    lva.reset();
    assertEquals(size, lva.size());
    // test clear
    lva.clear();
    assertEquals(0, lva.size());
}
Also used : ShortValue(org.apache.flink.types.ShortValue) Test(org.junit.Test)

Example 3 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class ShortValueSerializerTest method getTestData.

@Override
protected ShortValue[] getTestData() {
    Random rnd = new Random(874597969123412341L);
    int rndInt = rnd.nextInt(32767);
    return new ShortValue[] { new ShortValue((short) 0), new ShortValue((short) 1), new ShortValue((short) -1), new ShortValue((short) rndInt), new ShortValue((short) -rndInt), new ShortValue((short) -32767), new ShortValue((short) 32768) };
}
Also used : Random(java.util.Random) ShortValue(org.apache.flink.types.ShortValue)

Example 4 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class ShortValueArraySerializerTest method getTestData.

@Override
protected ShortValueArray[] getTestData() {
    int defaultElements = ShortValueArray.DEFAULT_CAPACITY_IN_BYTES / ShortValueArray.ELEMENT_LENGTH_IN_BYTES;
    Random rnd = new Random(874597969123412341L);
    int rndLong = rnd.nextInt();
    ShortValueArray lva0 = new ShortValueArray();
    ShortValueArray lva1 = new ShortValueArray();
    lva1.addAll(lva0);
    lva1.add(new ShortValue((short) 0));
    ShortValueArray lva2 = new ShortValueArray();
    lva2.addAll(lva1);
    lva2.add(new ShortValue((short) 1));
    ShortValueArray lva3 = new ShortValueArray();
    lva3.addAll(lva2);
    lva3.add(new ShortValue((short) -1));
    ShortValueArray lva4 = new ShortValueArray();
    lva4.addAll(lva3);
    lva4.add(new ShortValue(Short.MAX_VALUE));
    ShortValueArray lva5 = new ShortValueArray();
    lva5.addAll(lva4);
    lva5.add(new ShortValue(Short.MIN_VALUE));
    ShortValueArray lva6 = new ShortValueArray();
    lva6.addAll(lva5);
    lva6.add(new ShortValue((short) rndLong));
    ShortValueArray lva7 = new ShortValueArray();
    lva7.addAll(lva6);
    lva7.add(new ShortValue((short) -rndLong));
    ShortValueArray lva8 = new ShortValueArray();
    lva8.addAll(lva7);
    for (int i = 0; i < 1.5 * defaultElements; i++) {
        lva8.add(new ShortValue((short) i));
    }
    lva8.addAll(lva8);
    return new ShortValueArray[] { lva0, lva1, lva2, lva3, lva4, lva5, lva6, lva7, lva8 };
}
Also used : Random(java.util.Random) ShortValue(org.apache.flink.types.ShortValue)

Example 5 with ShortValue

use of org.apache.flink.types.ShortValue in project flink by apache.

the class ShortValueComparatorTest method getSortedTestData.

@Override
protected ShortValue[] getSortedTestData() {
    Random rnd = new Random(874597969123412338L);
    short rndShort = Integer.valueOf(rnd.nextInt()).shortValue();
    if (rndShort < 0) {
        rndShort = Integer.valueOf(-rndShort).shortValue();
    }
    if (rndShort == Short.MAX_VALUE) {
        rndShort -= 3;
    }
    if (rndShort <= 2) {
        rndShort += 3;
    }
    return new ShortValue[] { new ShortValue(Short.MIN_VALUE), new ShortValue(Integer.valueOf(-rndShort).shortValue()), new ShortValue(Integer.valueOf(-1).shortValue()), new ShortValue(Integer.valueOf(0).shortValue()), new ShortValue(Integer.valueOf(1).shortValue()), new ShortValue(Integer.valueOf(2).shortValue()), new ShortValue(Integer.valueOf(rndShort).shortValue()), new ShortValue(Short.MAX_VALUE) };
}
Also used : Random(java.util.Random) ShortValue(org.apache.flink.types.ShortValue)

Aggregations

ShortValue (org.apache.flink.types.ShortValue)10 Test (org.junit.Test)4 Random (java.util.Random)3 LongValueToUnsignedShortValue (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToUnsignedShortValue)2 DoubleToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleToLongValueWithProperHashCode)1 DoubleValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.DoubleValueToLongValueWithProperHashCode)1 LongValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.LongValueToLongValueWithProperHashCode)1 StringToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.StringToLongValueWithProperHashCode)1 StringValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.StringValueToLongValueWithProperHashCode)1 UnsignedByteToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedByteToLongValueWithProperHashCode)1 UnsignedByteValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedByteValueToLongValueWithProperHashCode)1 UnsignedFloatToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedFloatToLongValueWithProperHashCode)1 UnsignedFloatValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedFloatValueToLongValueWithProperHashCode)1 UnsignedIntToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedIntToLongValueWithProperHashCode)1 UnsignedShortToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortToLongValueWithProperHashCode)1 UnsignedShortValueToLongValueWithProperHashCode (org.apache.flink.graph.drivers.transform.GraphKeyTypeTransform.UnsignedShortValueToLongValueWithProperHashCode)1 LongValue (org.apache.flink.types.LongValue)1