@SafeVarargs
final <S, T> void testRoundTrip(Class<? extends S> keyType, Class<? extends T> valueType,
Pair<S, T>... data) throws Exception {
TileSerializer<Pair<S, T>> serializer = new PairAvroSerializer<>(keyType, valueType, CodecFactory.nullCodec());
int n = data.length;
int size = (int) Math.ceil(Math.sqrt(n));
TileData<Pair<S, T>> input = new DenseTileData<>(new TileIndex(0, 0, 0, size, size));
for (int y=0; y<size; ++y) {
for (int x=0; x<size; ++x) {
int i = ((x+size*y));
if (i < n) input.setBin(x, y, data[i]);
}
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
serializer.serialize(input, baos);
baos.flush();
baos.close();
ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray());
TileData<Pair<S, T>> output = serializer.deserialize(new TileIndex(1, 1, 1, size, size), bais);
Assert.assertEquals(input.getDefinition(), output.getDefinition());
for (int y=0; y<size; ++y) {
for (int x=0; x<size; ++x) {
Assert.assertEquals(input.getBin(x, y), output.getBin(x, y));
}
}
}