Switch to Maven project.
This commit is contained in:
		@@ -0,0 +1,112 @@
 | 
			
		||||
package org.insa.graphes.model;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
import org.insa.graphs.model.RoadInformation;
 | 
			
		||||
import org.insa.graphs.model.RoadInformation.RoadType;
 | 
			
		||||
import org.junit.BeforeClass;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
public class GraphTest {
 | 
			
		||||
 | 
			
		||||
    // Small graph use for tests
 | 
			
		||||
    private static Graph graph;
 | 
			
		||||
 | 
			
		||||
    // List of nodes
 | 
			
		||||
    private static Node[] nodes;
 | 
			
		||||
 | 
			
		||||
    @BeforeClass
 | 
			
		||||
    public static void initAll() throws IOException {
 | 
			
		||||
 | 
			
		||||
        // Create nodes
 | 
			
		||||
        nodes = new Node[5];
 | 
			
		||||
        for (int i = 0; i < nodes.length; ++i) {
 | 
			
		||||
            nodes[i] = new Node(i, null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Node.linkNodes(nodes[0], nodes[1], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
 | 
			
		||||
                new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[0], nodes[2], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
 | 
			
		||||
                new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[0], nodes[4], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[1], nodes[2], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
 | 
			
		||||
                new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[2], nodes[3], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[2], nodes[3], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[2], nodes[3], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[3], nodes[0], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
 | 
			
		||||
                new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[3], nodes[4], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[4], nodes[0], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
 | 
			
		||||
        graph = new Graph("ID", "", Arrays.asList(nodes), null);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return List of arcs between a and b.
 | 
			
		||||
     */
 | 
			
		||||
    private List<Arc> getArcsBetween(Node a, Node b) {
 | 
			
		||||
        List<Arc> arcs = new ArrayList<>();
 | 
			
		||||
        for (Arc arc: a.getSuccessors()) {
 | 
			
		||||
            if (arc.getDestination().equals(b)) {
 | 
			
		||||
                arcs.add(arc);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return arcs;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testTranspose() {
 | 
			
		||||
        Graph transpose = graph.transpose();
 | 
			
		||||
 | 
			
		||||
        // Basic asserts...
 | 
			
		||||
        assertEquals("R/" + graph.getMapId(), transpose.getMapId());
 | 
			
		||||
        assertEquals(graph.size(), transpose.size());
 | 
			
		||||
 | 
			
		||||
        final int expNbSucc[] = { 4, 2, 2, 4, 2 };
 | 
			
		||||
        for (int i = 0; i < expNbSucc.length; ++i) {
 | 
			
		||||
            assertEquals(expNbSucc[i], transpose.get(i).getNumberOfSuccessors());
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(0), transpose.get(1)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(0), transpose.get(2)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(0), transpose.get(3)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(0), transpose.get(4)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(1), transpose.get(0)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(1), transpose.get(2)).size());
 | 
			
		||||
        assertEquals(0, getArcsBetween(transpose.get(1), transpose.get(3)).size());
 | 
			
		||||
        assertEquals(0, getArcsBetween(transpose.get(1), transpose.get(4)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(2), transpose.get(0)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(2), transpose.get(1)).size());
 | 
			
		||||
        assertEquals(0, getArcsBetween(transpose.get(2), transpose.get(3)).size());
 | 
			
		||||
        assertEquals(0, getArcsBetween(transpose.get(2), transpose.get(4)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(3), transpose.get(0)).size());
 | 
			
		||||
        assertEquals(0, getArcsBetween(transpose.get(3), transpose.get(1)).size());
 | 
			
		||||
        assertEquals(3, getArcsBetween(transpose.get(3), transpose.get(2)).size());
 | 
			
		||||
        assertEquals(0, getArcsBetween(transpose.get(3), transpose.get(4)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(4), transpose.get(0)).size());
 | 
			
		||||
        assertEquals(0, getArcsBetween(transpose.get(4), transpose.get(1)).size());
 | 
			
		||||
        assertEquals(0, getArcsBetween(transpose.get(4), transpose.get(2)).size());
 | 
			
		||||
        assertEquals(1, getArcsBetween(transpose.get(4), transpose.get(3)).size());
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,92 @@
 | 
			
		||||
package org.insa.graphes.model;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
import org.insa.graphs.model.RoadInformation;
 | 
			
		||||
import org.insa.graphs.model.RoadInformation.RoadType;
 | 
			
		||||
import org.junit.Before;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
public class NodeTest {
 | 
			
		||||
 | 
			
		||||
    // List of nodes
 | 
			
		||||
    private Node[] nodes;
 | 
			
		||||
 | 
			
		||||
    @Before
 | 
			
		||||
    public void initAll() throws IOException {
 | 
			
		||||
 | 
			
		||||
        // Create nodes
 | 
			
		||||
        nodes = new Node[6];
 | 
			
		||||
        for (int i = 0; i < nodes.length; ++i) {
 | 
			
		||||
            nodes[i] = new Node(i, null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        Node.linkNodes(nodes[0], nodes[1], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
 | 
			
		||||
                new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[0], nodes[2], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
 | 
			
		||||
                new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[0], nodes[4], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[1], nodes[2], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
 | 
			
		||||
                new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[2], nodes[3], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[2], nodes[3], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[2], nodes[3], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[3], nodes[0], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, false, 1, null),
 | 
			
		||||
                new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[3], nodes[4], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
        Node.linkNodes(nodes[4], nodes[0], 0,
 | 
			
		||||
                new RoadInformation(RoadType.UNCLASSIFIED, null, true, 1, null), new ArrayList<>());
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * @return The first arc between from a to b, or null.
 | 
			
		||||
     */
 | 
			
		||||
    private Arc getFirstArcBetween(Node a, Node b) {
 | 
			
		||||
        for (Arc arc: a.getSuccessors()) {
 | 
			
		||||
            if (arc.getDestination().equals(b)) {
 | 
			
		||||
                return arc;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
        return null;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testGetNumberOfSuccessors() {
 | 
			
		||||
        final int[] expNbSucc = { 4, 2, 5, 2, 1, 0 };
 | 
			
		||||
        assertEquals(expNbSucc.length, nodes.length);
 | 
			
		||||
        for (int i = 0; i < expNbSucc.length; ++i) {
 | 
			
		||||
            assertEquals(expNbSucc[i], nodes[i].getNumberOfSuccessors());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testHasSuccessors() {
 | 
			
		||||
        final int[] expNbSucc = { 4, 2, 5, 2, 1, 0 };
 | 
			
		||||
        assertEquals(expNbSucc.length, nodes.length);
 | 
			
		||||
        for (int i = 0; i < expNbSucc.length; ++i) {
 | 
			
		||||
            assertEquals(expNbSucc[i] != 0, nodes[i].hasSuccessors());
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testLinkNodes() {
 | 
			
		||||
        assertEquals(getFirstArcBetween(nodes[0], nodes[1]).getRoadInformation(),
 | 
			
		||||
                getFirstArcBetween(nodes[1], nodes[0]).getRoadInformation());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@@ -0,0 +1,243 @@
 | 
			
		||||
package org.insa.graphes.model;
 | 
			
		||||
 | 
			
		||||
import static org.junit.Assert.assertEquals;
 | 
			
		||||
import static org.junit.Assert.assertFalse;
 | 
			
		||||
import static org.junit.Assert.assertTrue;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
 | 
			
		||||
import org.insa.graphs.model.Arc;
 | 
			
		||||
import org.insa.graphs.model.Graph;
 | 
			
		||||
import org.insa.graphs.model.Node;
 | 
			
		||||
import org.insa.graphs.model.Path;
 | 
			
		||||
import org.insa.graphs.model.RoadInformation;
 | 
			
		||||
import org.insa.graphs.model.RoadInformation.RoadType;
 | 
			
		||||
import org.junit.BeforeClass;
 | 
			
		||||
import org.junit.Test;
 | 
			
		||||
 | 
			
		||||
public class PathTest {
 | 
			
		||||
 | 
			
		||||
    // Small graph use for tests
 | 
			
		||||
    private static Graph graph;
 | 
			
		||||
 | 
			
		||||
    // List of nodes
 | 
			
		||||
    private static Node[] nodes;
 | 
			
		||||
 | 
			
		||||
    // List of arcs in the graph, a2b is the arc from node A (0) to B (1).
 | 
			
		||||
    @SuppressWarnings("unused")
 | 
			
		||||
    private static Arc a2b, a2c, a2e, b2c, c2d_1, c2d_2, c2d_3, c2a, d2a, d2e, e2d;
 | 
			
		||||
 | 
			
		||||
    // Some paths...
 | 
			
		||||
    private static Path emptyPath, singleNodePath, shortPath, longPath, loopPath, longLoopPath,
 | 
			
		||||
            invalidPath;
 | 
			
		||||
 | 
			
		||||
    @BeforeClass
 | 
			
		||||
    public static void initAll() throws IOException {
 | 
			
		||||
 | 
			
		||||
        // 10 and 20 meters per seconds
 | 
			
		||||
        RoadInformation speed10 = new RoadInformation(RoadType.MOTORWAY, null, true, 36, ""),
 | 
			
		||||
                speed20 = new RoadInformation(RoadType.MOTORWAY, null, true, 72, "");
 | 
			
		||||
 | 
			
		||||
        // Create nodes
 | 
			
		||||
        nodes = new Node[5];
 | 
			
		||||
        for (int i = 0; i < nodes.length; ++i) {
 | 
			
		||||
            nodes[i] = new Node(i, null);
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Add arcs...
 | 
			
		||||
        a2b = Node.linkNodes(nodes[0], nodes[1], 10, speed10, null);
 | 
			
		||||
        a2c = Node.linkNodes(nodes[0], nodes[2], 15, speed10, null);
 | 
			
		||||
        a2e = Node.linkNodes(nodes[0], nodes[4], 15, speed20, null);
 | 
			
		||||
        b2c = Node.linkNodes(nodes[1], nodes[2], 10, speed10, null);
 | 
			
		||||
        c2d_1 = Node.linkNodes(nodes[2], nodes[3], 20, speed10, null);
 | 
			
		||||
        c2d_2 = Node.linkNodes(nodes[2], nodes[3], 10, speed10, null);
 | 
			
		||||
        c2d_3 = Node.linkNodes(nodes[2], nodes[3], 15, speed20, null);
 | 
			
		||||
        d2a = Node.linkNodes(nodes[3], nodes[0], 15, speed10, null);
 | 
			
		||||
        d2e = Node.linkNodes(nodes[3], nodes[4], 22.8f, speed20, null);
 | 
			
		||||
        e2d = Node.linkNodes(nodes[4], nodes[0], 10, speed10, null);
 | 
			
		||||
 | 
			
		||||
        graph = new Graph("ID", "", Arrays.asList(nodes), null);
 | 
			
		||||
 | 
			
		||||
        emptyPath = new Path(graph, new ArrayList<Arc>());
 | 
			
		||||
        singleNodePath = new Path(graph, nodes[1]);
 | 
			
		||||
        shortPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1 }));
 | 
			
		||||
        longPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2e }));
 | 
			
		||||
        loopPath = new Path(graph, Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a }));
 | 
			
		||||
        longLoopPath = new Path(graph,
 | 
			
		||||
                Arrays.asList(new Arc[] { a2b, b2c, c2d_1, d2a, a2c, c2d_3, d2a, a2b, b2c }));
 | 
			
		||||
        invalidPath = new Path(graph, Arrays.asList(new Arc[] { a2b, c2d_1, d2e }));
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testConstructor() {
 | 
			
		||||
        assertEquals(graph, emptyPath.getGraph());
 | 
			
		||||
        assertEquals(graph, singleNodePath.getGraph());
 | 
			
		||||
        assertEquals(graph, shortPath.getGraph());
 | 
			
		||||
        assertEquals(graph, longPath.getGraph());
 | 
			
		||||
        assertEquals(graph, loopPath.getGraph());
 | 
			
		||||
        assertEquals(graph, longLoopPath.getGraph());
 | 
			
		||||
        assertEquals(graph, invalidPath.getGraph());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test(expected = UnsupportedOperationException.class)
 | 
			
		||||
    public void testImmutability() {
 | 
			
		||||
        emptyPath.getArcs().add(a2b);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testIsEmpty() {
 | 
			
		||||
        assertTrue(emptyPath.isEmpty());
 | 
			
		||||
 | 
			
		||||
        assertFalse(singleNodePath.isEmpty());
 | 
			
		||||
        assertFalse(shortPath.isEmpty());
 | 
			
		||||
        assertFalse(longPath.isEmpty());
 | 
			
		||||
        assertFalse(loopPath.isEmpty());
 | 
			
		||||
        assertFalse(longLoopPath.isEmpty());
 | 
			
		||||
        assertFalse(invalidPath.isEmpty());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testSize() {
 | 
			
		||||
        assertEquals(0, emptyPath.size());
 | 
			
		||||
        assertEquals(1, singleNodePath.size());
 | 
			
		||||
        assertEquals(4, shortPath.size());
 | 
			
		||||
        assertEquals(5, longPath.size());
 | 
			
		||||
        assertEquals(5, loopPath.size());
 | 
			
		||||
        assertEquals(10, longLoopPath.size());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testIsValid() {
 | 
			
		||||
        assertTrue(emptyPath.isValid());
 | 
			
		||||
        assertTrue(singleNodePath.isValid());
 | 
			
		||||
        assertTrue(shortPath.isValid());
 | 
			
		||||
        assertTrue(longPath.isValid());
 | 
			
		||||
        assertTrue(loopPath.isValid());
 | 
			
		||||
        assertTrue(longLoopPath.isValid());
 | 
			
		||||
 | 
			
		||||
        assertFalse(invalidPath.isValid());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testGetLength() {
 | 
			
		||||
        assertEquals(0, emptyPath.getLength(), 1e-6);
 | 
			
		||||
        assertEquals(0, singleNodePath.getLength(), 1e-6);
 | 
			
		||||
        assertEquals(40, shortPath.getLength(), 1e-6);
 | 
			
		||||
        assertEquals(62.8, longPath.getLength(), 1e-6);
 | 
			
		||||
        assertEquals(55, loopPath.getLength(), 1e-6);
 | 
			
		||||
        assertEquals(120, longLoopPath.getLength(), 1e-6);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testGetTravelTime() {
 | 
			
		||||
        // Note: 18 km/h = 5m/s
 | 
			
		||||
        assertEquals(0, emptyPath.getTravelTime(18), 1e-6);
 | 
			
		||||
        assertEquals(0, singleNodePath.getTravelTime(18), 1e-6);
 | 
			
		||||
        assertEquals(8, shortPath.getTravelTime(18), 1e-6);
 | 
			
		||||
        assertEquals(12.56, longPath.getTravelTime(18), 1e-6);
 | 
			
		||||
        assertEquals(11, loopPath.getTravelTime(18), 1e-6);
 | 
			
		||||
        assertEquals(24, longLoopPath.getTravelTime(18), 1e-6);
 | 
			
		||||
 | 
			
		||||
        // Note: 28.8 km/h = 8m/s
 | 
			
		||||
        assertEquals(0, emptyPath.getTravelTime(28.8), 1e-6);
 | 
			
		||||
        assertEquals(0, singleNodePath.getTravelTime(28.8), 1e-6);
 | 
			
		||||
        assertEquals(5, shortPath.getTravelTime(28.8), 1e-6);
 | 
			
		||||
        assertEquals(7.85, longPath.getTravelTime(28.8), 1e-6);
 | 
			
		||||
        assertEquals(6.875, loopPath.getTravelTime(28.8), 1e-6);
 | 
			
		||||
        assertEquals(15, longLoopPath.getTravelTime(28.8), 1e-6);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testGetMinimumTravelTime() {
 | 
			
		||||
        assertEquals(0, emptyPath.getMinimumTravelTime(), 1e-4);
 | 
			
		||||
        assertEquals(0, singleNodePath.getLength(), 1e-4);
 | 
			
		||||
        assertEquals(4, shortPath.getMinimumTravelTime(), 1e-4);
 | 
			
		||||
        assertEquals(5.14, longPath.getMinimumTravelTime(), 1e-4);
 | 
			
		||||
        assertEquals(5.5, loopPath.getMinimumTravelTime(), 1e-4);
 | 
			
		||||
        assertEquals(11.25, longLoopPath.getMinimumTravelTime(), 1e-4);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testCreateFastestPathFromNodes() {
 | 
			
		||||
        Path path;
 | 
			
		||||
        Arc[] expected;
 | 
			
		||||
 | 
			
		||||
        // Simple construction
 | 
			
		||||
        path = Path.createFastestPathFromNodes(graph,
 | 
			
		||||
                Arrays.asList(new Node[] { nodes[0], nodes[1], nodes[2] }));
 | 
			
		||||
        expected = new Arc[] { a2b, b2c };
 | 
			
		||||
        assertEquals(expected.length, path.getArcs().size());
 | 
			
		||||
        for (int i = 0; i < expected.length; ++i) {
 | 
			
		||||
            assertEquals(expected[i], path.getArcs().get(i));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Not so simple construction
 | 
			
		||||
        path = Path.createFastestPathFromNodes(graph,
 | 
			
		||||
                Arrays.asList(new Node[] { nodes[0], nodes[1], nodes[2], nodes[3] }));
 | 
			
		||||
        expected = new Arc[] { a2b, b2c, c2d_3 };
 | 
			
		||||
        assertEquals(expected.length, path.getArcs().size());
 | 
			
		||||
        for (int i = 0; i < expected.length; ++i) {
 | 
			
		||||
            assertEquals(expected[i], path.getArcs().get(i));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Trap construction!
 | 
			
		||||
        path = Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1] }));
 | 
			
		||||
        assertEquals(nodes[1], path.getOrigin());
 | 
			
		||||
        assertEquals(0, path.getArcs().size());
 | 
			
		||||
 | 
			
		||||
        // Trap construction - The return!
 | 
			
		||||
        path = Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[0]));
 | 
			
		||||
        assertEquals(null, path.getOrigin());
 | 
			
		||||
        assertEquals(0, path.getArcs().size());
 | 
			
		||||
        assertTrue(path.isEmpty());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test
 | 
			
		||||
    public void testCreateShortestPathFromNodes() {
 | 
			
		||||
        Path path;
 | 
			
		||||
        Arc[] expected;
 | 
			
		||||
 | 
			
		||||
        // Simple construction
 | 
			
		||||
        path = Path.createShortestPathFromNodes(graph,
 | 
			
		||||
                Arrays.asList(new Node[] { nodes[0], nodes[1], nodes[2] }));
 | 
			
		||||
        expected = new Arc[] { a2b, b2c };
 | 
			
		||||
        assertEquals(expected.length, path.getArcs().size());
 | 
			
		||||
        for (int i = 0; i < expected.length; ++i) {
 | 
			
		||||
            assertEquals(expected[i], path.getArcs().get(i));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Not so simple construction
 | 
			
		||||
        path = Path.createShortestPathFromNodes(graph,
 | 
			
		||||
                Arrays.asList(new Node[] { nodes[0], nodes[1], nodes[2], nodes[3] }));
 | 
			
		||||
        expected = new Arc[] { a2b, b2c, c2d_2 };
 | 
			
		||||
        assertEquals(expected.length, path.getArcs().size());
 | 
			
		||||
        for (int i = 0; i < expected.length; ++i) {
 | 
			
		||||
            assertEquals(expected[i], path.getArcs().get(i));
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Trap construction!
 | 
			
		||||
        path = Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1] }));
 | 
			
		||||
        assertEquals(nodes[1], path.getOrigin());
 | 
			
		||||
        assertEquals(0, path.getArcs().size());
 | 
			
		||||
 | 
			
		||||
        // Trap construction - The return!
 | 
			
		||||
        path = Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[0]));
 | 
			
		||||
        assertEquals(null, path.getOrigin());
 | 
			
		||||
        assertEquals(0, path.getArcs().size());
 | 
			
		||||
        assertTrue(path.isEmpty());
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test(expected = IllegalArgumentException.class)
 | 
			
		||||
    public void testCreateFastestPathFromNodesException() {
 | 
			
		||||
        Path.createFastestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] }));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    @Test(expected = IllegalArgumentException.class)
 | 
			
		||||
    public void testCreateShortestPathFromNodesException() {
 | 
			
		||||
        Path.createShortestPathFromNodes(graph, Arrays.asList(new Node[] { nodes[1], nodes[0] }));
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user