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));
}
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());
}
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) };
}
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 };
}
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) };
}
Aggregations