Thomas Vachuska | 24c849c | 2014-10-27 09:53:05 -0700 | [diff] [blame^] | 1 | /* |
| 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 | */ |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 19 | package org.onlab.graph; |
| 20 | |
| 21 | import com.google.common.collect.ImmutableSet; |
| 22 | import com.google.common.testing.EqualsTester; |
| 23 | import org.junit.Test; |
| 24 | |
| 25 | import java.util.Set; |
| 26 | |
| 27 | import static org.junit.Assert.assertEquals; |
| 28 | |
| 29 | /** |
| 30 | * Tests of the graph implementation. |
| 31 | */ |
| 32 | public 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 = |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 43 | 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)); |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 46 | |
| 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 | } |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 61 | |
| 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 | } |
tom | e348941 | 2014-08-29 02:30:38 -0700 | [diff] [blame] | 75 | } |