@Test public void testFloat () throws Exception { testRoundTripDense(new TypeDescriptor(Float.class), EMPTY, 0.0f, 0.5f, 0.333f, 0.25f, 0.2f, 0.166f, 0.142857f, 0.125f); testRoundTripSparse(new TypeDescriptor(Float.class), EMPTY, -3.5f, 0.0f, 0.5f, 0.333f, 0.25f); }
@Test public void testBZip () throws Exception { // Create our serializer KryoSerializer<List<Integer>> serializer = new KryoSerializer<>(new TypeDescriptor(List.class, new TypeDescriptor(Integer.class)), KryoSerializer.Codec.BZIP); // Create a large tile int xN = 256; int yN = 256; int zN = 100; TileIndex index = new TileIndex(0, 0, 0, xN, yN); TileData<List<Integer>> input = new DenseTileData<List<Integer>>(index); for (int x=0; x<xN; ++x) { for (int y=0; y<yN; ++y) { List<Integer> bin = new ArrayList<>(zN); for (int z=0; z<zN; ++z) bin.add((int) Math.floor(Math.random()*1024)); input.setBin(x, y, bin); } } // Write it out ByteArrayOutputStream baos = new ByteArrayOutputStream(); serializer.serialize(input, baos); baos.flush(); baos.close(); // Read it back in ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); TileData<List<Integer>> output = serializer.deserialize(index, bais); assertListTilesEqual(input, output); }
@Test public void testGZip () throws Exception { // Create our serializer KryoSerializer<List<Integer>> serializer = new KryoSerializer<>(new TypeDescriptor(List.class, new TypeDescriptor(Integer.class)), KryoSerializer.Codec.GZIP); // Create a large tile int xN = 256; int yN = 256; int zN = 100; TileIndex index = new TileIndex(0, 0, 0, xN, yN); TileData<List<Integer>> input = new DenseTileData<List<Integer>>(index); for (int x=0; x<xN; ++x) { for (int y=0; y<yN; ++y) { List<Integer> bin = new ArrayList<>(zN); for (int z=0; z<zN; ++z) bin.add((int) Math.floor(Math.random()*1024)); input.setBin(x, y, bin); } } // Write it out ByteArrayOutputStream baos = new ByteArrayOutputStream(); serializer.serialize(input, baos); baos.flush(); baos.close(); // Read it back in ByteArrayInputStream bais = new ByteArrayInputStream(baos.toByteArray()); TileData<List<Integer>> output = serializer.deserialize(index, bais); assertListTilesEqual(input, output); }
@Test public void testBoolean () throws Exception { testRoundTripDense(new TypeDescriptor(Boolean.class), EMPTY, true, false, true, true, false, true, false, false, true); testRoundTripSparse(new TypeDescriptor(Boolean.class), EMPTY, true, true, false); }
TileData<List<Integer>> output = serializer.deserialize(index, bais); assertListTilesEqual(input, output);
@Test public void testLong () throws Exception { testRoundTripDense(new TypeDescriptor(Long.class), EMPTY, 0L, 1L, 8L, 27L, 64L, 125L, 216L, 343L, 512L); testRoundTripSparse(new TypeDescriptor(Long.class), EMPTY, -3L, 1L, 8L, 27L, 64L); }
@Test public void testString () throws Exception { testRoundTripDense(new TypeDescriptor(String.class), EMPTY, "a", "bb", "ccc", "dddd", "eeeee", "ffffff", "ggggggg", "hhhhhhhh"); testRoundTripSparse(new TypeDescriptor(String.class), EMPTY, "invalid", "a", "bb", "ccc", "dddd"); }
@Test public void testInteger () throws Exception { testRoundTripDense(new TypeDescriptor(Integer.class), EMPTY, 0, 1, 4, 9, 16, 25, 36, 49, 64); testRoundTripSparse(new TypeDescriptor(Integer.class), EMPTY, -1, 0, 1, 4, 9); }
@Test public void testDouble () throws Exception { testRoundTripDense(new TypeDescriptor(Double.class), EMPTY, 0.0, 1.1, 2.4, 3.9, 4.16, 5.25, 6.36, 7.49, 8.64); testRoundTripSparse(new TypeDescriptor(Double.class), EMPTY, -3.5, 1.1, 2.4, 3.9, 4.16); }
@Test public void testCustom () throws Exception { testRoundTripDense(new TypeDescriptor(CustomTestData.class), new Class<?>[] {CustomTestData.class}, new CustomTestData(1, 1.1, "one"), new CustomTestData(2, 2.2, "two"), new CustomTestData(3, 3.3, "three"), new CustomTestData(4, 4.4, "four")); testRoundTripSparse(new TypeDescriptor(CustomTestData.class), new Class<?>[] {CustomTestData.class}, new CustomTestData(-1, -1.1, "empty"), new CustomTestData(1, 1.1, "one"), new CustomTestData(2, 2.2, "two"), new CustomTestData(3, 3.3, "three"), new CustomTestData(4, 4.4, "four")); }