blob: abdcdbffd5013d994bf406d12e52f72f490d6eb6 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tome3489412014-08-29 02:30:38 -070019package org.onlab.graph;
20
21import com.google.common.collect.ImmutableSet;
22import com.google.common.testing.EqualsTester;
23import org.junit.Test;
24
25import java.util.Set;
26
27import static org.junit.Assert.assertEquals;
28
29/**
30 * Tests of the graph implementation.
31 */
32public class AdjacencyListsGraphTest {
33
34 private static final TestVertex A = new TestVertex("A");
35 private static final TestVertex B = new TestVertex("B");
36 private static final TestVertex C = new TestVertex("C");
37 private static final TestVertex D = new TestVertex("D");
38 private static final TestVertex E = new TestVertex("E");
39 private static final TestVertex F = new TestVertex("F");
40 private static final TestVertex G = new TestVertex("G");
41
42 private final Set<TestEdge> edges =
tom144de692014-08-29 11:38:44 -070043 ImmutableSet.of(new TestEdge(A, B, 1), new TestEdge(B, C, 1),
44 new TestEdge(C, D, 1), new TestEdge(D, A, 1),
45 new TestEdge(B, D, 1));
tome3489412014-08-29 02:30:38 -070046
47 @Test
48 public void equality() {
49 Set<TestVertex> vertexes = ImmutableSet.of(A, B, C, D, E, F);
50 Set<TestVertex> vertexes2 = ImmutableSet.of(A, B, C, D, E, F, G);
51
52 AdjacencyListsGraph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(vertexes, edges);
53 AdjacencyListsGraph<TestVertex, TestEdge> same = new AdjacencyListsGraph<>(vertexes, edges);
54 AdjacencyListsGraph<TestVertex, TestEdge> different = new AdjacencyListsGraph<>(vertexes2, edges);
55
56 new EqualsTester()
57 .addEqualityGroup(graph, same)
58 .addEqualityGroup(different)
59 .testEquals();
60 }
tom144de692014-08-29 11:38:44 -070061
62 @Test
63 public void basics() {
64 Set<TestVertex> vertexes = ImmutableSet.of(A, B, C, D, E, F);
65 AdjacencyListsGraph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(vertexes, edges);
66 assertEquals("incorrect vertex count", 6, graph.getVertexes().size());
67 assertEquals("incorrect edge count", 5, graph.getEdges().size());
68
69 assertEquals("incorrect egress edge count", 1, graph.getEdgesFrom(A).size());
70 assertEquals("incorrect ingress edge count", 1, graph.getEdgesTo(A).size());
71 assertEquals("incorrect ingress edge count", 1, graph.getEdgesTo(C).size());
72 assertEquals("incorrect egress edge count", 2, graph.getEdgesFrom(B).size());
73 assertEquals("incorrect ingress edge count", 2, graph.getEdgesTo(D).size());
74 }
tome3489412014-08-29 02:30:38 -070075}