tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 1 | package org.onlab.graph; |
| 2 | |
| 3 | import com.google.common.collect.ImmutableSet; |
| 4 | import com.google.common.testing.EqualsTester; |
| 5 | import org.junit.Test; |
| 6 | |
| 7 | import java.util.Set; |
| 8 | |
| 9 | import static org.junit.Assert.assertEquals; |
| 10 | |
| 11 | /** |
| 12 | * Tests of the graph implementation. |
| 13 | */ |
| 14 | public class AdjacencyListsGraphTest { |
| 15 | |
| 16 | private static final TestVertex A = new TestVertex("A"); |
| 17 | private static final TestVertex B = new TestVertex("B"); |
| 18 | private static final TestVertex C = new TestVertex("C"); |
| 19 | private static final TestVertex D = new TestVertex("D"); |
| 20 | private static final TestVertex E = new TestVertex("E"); |
| 21 | private static final TestVertex F = new TestVertex("F"); |
| 22 | private static final TestVertex G = new TestVertex("G"); |
| 23 | |
| 24 | private final Set<TestEdge> edges = |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 25 | ImmutableSet.of(new TestEdge(A, B, 1), new TestEdge(B, C, 1), |
| 26 | new TestEdge(C, D, 1), new TestEdge(D, A, 1), |
| 27 | new TestEdge(B, D, 1)); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 28 | |
| 29 | @Test |
| 30 | public void equality() { |
| 31 | Set<TestVertex> vertexes = ImmutableSet.of(A, B, C, D, E, F); |
| 32 | Set<TestVertex> vertexes2 = ImmutableSet.of(A, B, C, D, E, F, G); |
| 33 | |
| 34 | AdjacencyListsGraph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(vertexes, edges); |
| 35 | AdjacencyListsGraph<TestVertex, TestEdge> same = new AdjacencyListsGraph<>(vertexes, edges); |
| 36 | AdjacencyListsGraph<TestVertex, TestEdge> different = new AdjacencyListsGraph<>(vertexes2, edges); |
| 37 | |
| 38 | new EqualsTester() |
| 39 | .addEqualityGroup(graph, same) |
| 40 | .addEqualityGroup(different) |
| 41 | .testEquals(); |
| 42 | } |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 43 | |
| 44 | @Test |
| 45 | public void basics() { |
| 46 | Set<TestVertex> vertexes = ImmutableSet.of(A, B, C, D, E, F); |
| 47 | AdjacencyListsGraph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(vertexes, edges); |
| 48 | assertEquals("incorrect vertex count", 6, graph.getVertexes().size()); |
| 49 | assertEquals("incorrect edge count", 5, graph.getEdges().size()); |
| 50 | |
| 51 | assertEquals("incorrect egress edge count", 1, graph.getEdgesFrom(A).size()); |
| 52 | assertEquals("incorrect ingress edge count", 1, graph.getEdgesTo(A).size()); |
| 53 | assertEquals("incorrect ingress edge count", 1, graph.getEdgesTo(C).size()); |
| 54 | assertEquals("incorrect egress edge count", 2, graph.getEdgesFrom(B).size()); |
| 55 | assertEquals("incorrect ingress edge count", 2, graph.getEdgesTo(D).size()); |
| 56 | } |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 57 | } |