blob: 90895503f41d3c2c5005b0548a74c2bbf15c5017 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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
Thomas Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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.
Thomas Vachuska24c849c2014-10-27 09:53:05 -070015 */
tome3489412014-08-29 02:30:38 -070016package org.onlab.graph;
17
18import com.google.common.collect.ImmutableSet;
19import com.google.common.testing.EqualsTester;
20import org.junit.Test;
21
22import java.util.Set;
23
24import static org.junit.Assert.assertEquals;
25
26/**
27 * Tests of the graph implementation.
28 */
29public class AdjacencyListsGraphTest {
30
31 private static final TestVertex A = new TestVertex("A");
32 private static final TestVertex B = new TestVertex("B");
33 private static final TestVertex C = new TestVertex("C");
34 private static final TestVertex D = new TestVertex("D");
35 private static final TestVertex E = new TestVertex("E");
36 private static final TestVertex F = new TestVertex("F");
37 private static final TestVertex G = new TestVertex("G");
38
39 private final Set<TestEdge> edges =
tom144de692014-08-29 11:38:44 -070040 ImmutableSet.of(new TestEdge(A, B, 1), new TestEdge(B, C, 1),
41 new TestEdge(C, D, 1), new TestEdge(D, A, 1),
42 new TestEdge(B, D, 1));
tome3489412014-08-29 02:30:38 -070043
44 @Test
45 public void equality() {
46 Set<TestVertex> vertexes = ImmutableSet.of(A, B, C, D, E, F);
47 Set<TestVertex> vertexes2 = ImmutableSet.of(A, B, C, D, E, F, G);
48
49 AdjacencyListsGraph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(vertexes, edges);
50 AdjacencyListsGraph<TestVertex, TestEdge> same = new AdjacencyListsGraph<>(vertexes, edges);
51 AdjacencyListsGraph<TestVertex, TestEdge> different = new AdjacencyListsGraph<>(vertexes2, edges);
52
53 new EqualsTester()
54 .addEqualityGroup(graph, same)
55 .addEqualityGroup(different)
56 .testEquals();
57 }
tom144de692014-08-29 11:38:44 -070058
59 @Test
60 public void basics() {
61 Set<TestVertex> vertexes = ImmutableSet.of(A, B, C, D, E, F);
62 AdjacencyListsGraph<TestVertex, TestEdge> graph = new AdjacencyListsGraph<>(vertexes, edges);
63 assertEquals("incorrect vertex count", 6, graph.getVertexes().size());
64 assertEquals("incorrect edge count", 5, graph.getEdges().size());
65
66 assertEquals("incorrect egress edge count", 1, graph.getEdgesFrom(A).size());
67 assertEquals("incorrect ingress edge count", 1, graph.getEdgesTo(A).size());
68 assertEquals("incorrect ingress edge count", 1, graph.getEdgesTo(C).size());
69 assertEquals("incorrect egress edge count", 2, graph.getEdgesFrom(B).size());
70 assertEquals("incorrect ingress edge count", 2, graph.getEdgesTo(D).size());
71 }
tome3489412014-08-29 02:30:38 -070072}