Debian Codegraph @

test/uk/me/parabola/imgfmt/UtilsTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2008 Steve Ratcliffe
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 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: 30-Nov-2008
16 */
17 package uk.me.parabola.imgfmt;
18
19 import static org.junit.Assert.*;
20
21 import java.util.HashMap;
22
23 import org.junit.Test;
24
25 import uk.me.parabola.imgfmt.app.Coord;
26
27
28 public class UtilsTest {
29
30 /**
31 * Very simple test that the coord2Long method is working.
32 */
33 @Test
34 public void testCoord2Long() {
35 HashMap<Long,Coord> map = new HashMap<>();
36 Coord lowerLeft = new Coord(-89.0,-179.0);
37 Coord upperRight = new Coord(89.0,179.0);
38 for (int latHp = -10; latHp < 10; latHp++){
39 for (int lonHp = -10; lonHp < 10; lonHp++){
40 for (int k = 0; k < 3;k++){
41 Coord co;
42 if (k == 0)
43 co = Coord.makeHighPrecCoord(latHp, lonHp);
44 else if (k == 1)
45 co = Coord.makeHighPrecCoord(latHp+lowerLeft.getHighPrecLat(), lonHp+lowerLeft.getHighPrecLon());
46 else
47 co = Coord.makeHighPrecCoord(latHp+upperRight.getHighPrecLat(), lonHp+upperRight.getHighPrecLon());
48 long key = Utils.coord2Long(co);
49 Coord old = map.put(key, co);
50 assertTrue("key not unique", old==null);
51 }
52 }
53 }
54 }
55
56 @Test
57 public void testRoundUp() {
58 assertEquals(1, Utils.roundUp(1, 0));
59 assertEquals(-1, Utils.roundUp(-1, 0));
60 assertEquals(2, Utils.roundUp(1, 1));
61 assertEquals(0, Utils.roundUp(-1, 1));
62 assertEquals(2, Utils.roundUp(2, 1));
63 assertEquals(-2, Utils.roundUp(-2, 1));
64 }
65 }