Debian Codegraph @

test/uk/me/parabola/imgfmt/app/dem/DemTileTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2018.
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 3 or
6 * version 2 as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
12 */
13 package uk.me.parabola.imgfmt.app.dem;
14
15 import static org.junit.Assert.assertEquals;
16
17 import java.util.Arrays;
18
19 import org.junit.Test;
20
21 import uk.me.parabola.mkgmap.reader.hgt.HGTReader;
22
23 /**
24 * Test some inputs for class DemTile.
25 * @author Gerd Petermann
26 *
27 */
28 public class DemTileTest {
29
30 @Test
31 public void testKnownBitstream() throws Exception {
32 // Example from Dem-Daten.pdf by Frank Stinner
33 short[] realHeights = new short[64*64];
34 realHeights[63 * 64] = 3;
35 DEMTile dt = new DEMTile(0, 0, 64,64, realHeights);
36 int bsLen = dt.getBitStreamLen();
37 byte[] exprectedRes = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xC0, 0x2e};
38 assertEquals(12, bsLen);
39 String res = Arrays.toString(dt.getBitStream());
40 assertEquals(Arrays.toString(exprectedRes), res);
41 }
42
43 @Test
44 public void testAllZero() throws Exception {
45 short[] realHeights = new short[64*64];
46 DEMTile dt = new DEMTile(0, 0, 64,64, realHeights);
47 int bsLen = dt.getBitStreamLen();
48 assertEquals(0, bsLen);
49 assertEquals(0, dt.getBaseHeight());
50 assertEquals(0, dt.getMaxDeltaHeight());
51 assertEquals(0, dt.getEncodingType());
52 }
53
54 @Test
55 public void testAllOne() throws Exception {
56 short[] realHeights = new short[64*64];
57 Arrays.fill(realHeights, (short)1);
58 DEMTile dt = new DEMTile(0, 0, 64,64, realHeights);
59 int bsLen = dt.getBitStreamLen();
60 assertEquals(0, bsLen);
61 assertEquals(1, dt.getBaseHeight());
62 assertEquals(0, dt.getMaxDeltaHeight());
63 assertEquals(0, dt.getEncodingType());
64 }
65
66 @Test
67 public void testAllZeroOneUndef() throws Exception {
68 short[] realHeights = new short[64*64];
69 realHeights[63 * 64] = HGTReader.UNDEF;
70 byte[] exprectedRes = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xC0, 0x3e};
71 DEMTile dt = new DEMTile(0, 0, 64,64, realHeights);
72 int bsLen = dt.getBitStreamLen();
73 assertEquals(12, bsLen);
74 assertEquals(0, dt.getBaseHeight());
75 assertEquals(1, dt.getMaxDeltaHeight());
76 assertEquals(2, dt.getEncodingType());
77 String res = Arrays.toString(dt.getBitStream());
78 assertEquals(Arrays.toString(exprectedRes), res);
79 }
80 }