Debian Codegraph @

test/uk/me/parabola/util/KdTreeTest.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2014 Gerd Petermann
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.util;
14
15 import static org.junit.Assert.assertFalse;
16
17 import org.junit.Test;
18
19 import uk.me.parabola.imgfmt.app.Coord;
20 import uk.me.parabola.mkgmap.general.MapPoint;
21
22 public class KdTreeTest {
23
24 @Test
25 public void findNextPointTest(){
26 KdTree<MapPoint> t = new KdTree<>( );
27
28 int [][]test = {{70,20}, {50,40}, {90,60}, {20,30}, {40,70}, {80,10}, {-10,20}, {-30,-40} } ;
29 Coord []testCoords = new Coord[test.length];
30
31 for( int i = 0; i < test.length; i++ )
32 {
33 MapPoint p = new MapPoint();
34 testCoords[i] = new Coord(test[i][0],test[i][1]);
35 p.setLocation(testCoords[i]);
36 t.add(p);
37 }
38 // compare naive search result with kd--tree result
39 MapPoint toFind = new MapPoint();
40 for (int x = -100; x < 100; x++){
41 for (int y = -100; y < 100; y++){
42 Coord co = new Coord(x,y);
43 double minDist = Double.MAX_VALUE;
44
45 for (int i = 0; i<testCoords.length; i++){
46 Double dist = testCoords[i].distanceInDegreesSquared(co);
47 if (dist < minDist){
48 minDist = dist;
49 }
50 }
51 toFind.setLocation(co);
52 MapPoint next = t.findNextPoint(toFind);
53 double dist = next.getLocation().distanceInDegreesSquared(co);
54 double delta = Math.abs(dist - minDist);
55 // if this test fails because
56 assertFalse("delta should be 0.0: " + delta, delta != 0.0);
57 }
58 }
59 }
60 }