Moved LaTeX test file and restored MySearcherTest; fixed merge conflict: rearranged...
[ailab2.git] / test / GraphTest.java
blob6833af346f48f0c1e7350091729fffc0a6aa5e20
1 import junit.framework.*;
3 /**
4 * GraphTest
6 * @author "Anton Johansson" <anton.johansson@gmail.com>
7 */
8 public class GraphTest extends TestCase {
9 public GraphTest(String name) {
10 super(name);
13 public void testEmpty() {
14 Graph g = new Graph(11, 24);
15 assertTrue(g.isEmpty());
16 g.insertNode("lund", 0, 0);
17 assertFalse(g.isEmpty());
18 g.insertNode("malmö", 3, 4);
19 g.deleteNode(g.getNode("lund"));
20 assertFalse(g.isEmpty());
21 g.deleteNode(g.getNode("malmö"));
22 assertTrue(g.isEmpty());
26 public void testEdges() {
27 Graph g = new Graph(11, 24);
28 g.insertNode("lund", 1, 2);
29 g.insertNode("malmö", 1, 2);
30 g.insertNode("eslöv", 1, 2);
31 g.insertNode("umeå", 1, 2);
32 g.insertNode("stockholm", 2, 4);
33 g.insertEdge("lund", "malmö", 100.0);
34 g.insertEdge("lund", "eslöv", 200.0);
35 g.insertEdge("eslöv", "umeå", 300.0);
36 g.insertEdge("lund", "stockholm", 400.0);
37 assertEquals("malmö", g.getNode("malmö").getName());
38 assertEquals("umeå", g.getNode("umeå").getName());
39 assertFalse("malmö" != g.getNode("malmö").getName());
40 assertEquals(100.0, g.getWeight("lund", "malmö"));
41 assertEquals(200.0, g.getWeight("lund", "eslöv"));
42 assertEquals(300.0, g.getWeight("eslöv", "umeå"));
43 //assertEquals(300.0, g.getWeight("umeå", "eslöv"));
44 assertEquals(400.0, g.getWeight("lund", "stockholm"));
47 public void testSetGetDistance() {
48 Graph g = new Graph(11, 24);
49 GraphNode lund = g.insertNode("lund", 0, 0);
50 GraphNode malmo = g.insertNode("malmö", 0, 2);
51 GraphNode eslov = g.insertNode("eslöv", 5, 0);
52 GraphNode umea = g.insertNode("umeå", 4, 7);
53 GraphNode kiruna = g.insertNode("kiruna", 9, 15);
54 // g.insertNode("stockholm", 2, 4);
55 assertEquals(0, lund.getX());
56 assertEquals(0, lund.getY());
58 assertEquals(0, malmo.getX());
59 assertEquals(2, malmo.getY());
61 lund.setDistanceToGoal(malmo);
62 assertEquals(2.0, lund.getDistanceToGoal());
64 lund.setDistanceToGoal(eslov);
65 assertEquals(5.0, lund.getDistanceToGoal());
67 lund.setDistanceToGoal(umea);
68 // (sqrt (+ (expt 4 2) (expt 7 2)))
69 assertEquals(8.06225774829855, lund.getDistanceToGoal(), 0.0000000001);
71 umea.setDistanceToGoal(kiruna);
72 // (sqrt (+ (expt (- 4 9) 2) (expt (- 7 15) 2)))
73 assertEquals(9.433981132056603, umea.getDistanceToGoal(), 0.0000000001);