Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2014-present Open Networking Laboratory |
Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 3 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 4 | * 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 Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 7 | * |
Thomas Vachuska | 4f1a60c | 2014-10-28 13:39:07 -0700 | [diff] [blame] | 8 | * 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 Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame] | 15 | */ |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 16 | package org.onlab.graph; |
| 17 | |
| 18 | import com.google.common.collect.ImmutableSet; |
| 19 | import com.google.common.testing.EqualsTester; |
| 20 | import org.junit.Test; |
| 21 | |
| 22 | import java.util.Set; |
| 23 | |
| 24 | import static org.junit.Assert.assertEquals; |
| 25 | |
| 26 | /** |
| 27 | * Tests of the graph implementation. |
| 28 | */ |
| 29 | public 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 = |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 40 | 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)); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 43 | |
| 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 | } |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 58 | |
| 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 | } |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 72 | } |