blob: 9105891b4c3df3b163989325d1e8705e2dea58bc [file] [log] [blame]
tome3489412014-08-29 02:30:38 -07001package org.onlab.graph;
2
3import com.google.common.collect.ImmutableSet;
4import com.google.common.testing.EqualsTester;
5import org.junit.Test;
6
7import java.util.Set;
8
9import static org.junit.Assert.assertEquals;
10
11/**
12 * Tests of the graph implementation.
13 */
14public 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 =
tom144de692014-08-29 11:38:44 -070025 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));
tome3489412014-08-29 02:30:38 -070028
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 }
tom144de692014-08-29 11:38:44 -070043
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 }
tome3489412014-08-29 02:30:38 -070057}