1   /*
2    * Copyright 2004 Ronald Blaschke.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package org.rblasch.convert.dijkstra;
17  
18  import junit.framework.Test;
19  import junit.framework.TestCase;
20  import junit.framework.TestSuite;
21  import org.rblasch.convert.graph.Edge;
22  import org.rblasch.convert.graph.ListPath;
23  import org.rblasch.convert.graph.Path;
24  import org.rblasch.convert.graph.Vertex;
25  
26  import java.util.Iterator;
27  import java.util.LinkedList;
28  import java.util.List;
29  
30  public class ListPathTest extends TestCase {
31      public static void main(final String[] argv) {
32          junit.textui.TestRunner.run(suite());
33      }
34  
35      public static Test suite() {
36          final TestSuite suite = new TestSuite();
37          suite.addTestSuite(ListPathTest.class);
38          return suite;
39      }
40  
41      public ListPathTest(final String name) {
42          super(name);
43      }
44  
45      public void testTrivialPath() throws Exception {
46          final Vertex v = new TestVertex();
47          final List pathList = new LinkedList();
48          pathList.add(v);
49          final Path path = new ListPath(pathList);
50  
51          assertEquals(v, path.getStart());
52          assertEquals(v, path.getEnd());
53  
54          assertTrue(path.getEdges().isEmpty());
55  
56          assertEquals(1, path.getVertices().size());
57          assertEquals(v, path.getVertices().get(0));
58  
59          final Iterator i = path.iterator();
60          assertEquals(v, i.next());
61          assertFalse(i.hasNext());
62      }
63  
64      public void testSimplePath() throws Exception {
65          final Vertex v1 = new TestVertex();
66          final Edge e = new TestEdge();
67          final Vertex v2 = new TestVertex();
68          final List pathList = new LinkedList();
69          pathList.add(v1);
70          pathList.add(e);
71          pathList.add(v2);
72          final Path path = new ListPath(pathList);
73  
74          assertEquals(v1, path.getStart());
75          assertEquals(v2, path.getEnd());
76  
77          assertEquals(1, path.getEdges().size());
78          assertEquals(e, path.getEdges().get(0));
79  
80          assertEquals(2, path.getVertices().size());
81          assertEquals(v1, path.getVertices().get(0));
82          assertEquals(v2, path.getVertices().get(1));
83  
84          final Iterator i = path.iterator();
85          assertEquals(v1, i.next());
86          assertEquals(e, i.next());
87          assertEquals(v2, i.next());
88          assertFalse(i.hasNext());
89      }
90  
91  }