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 | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 16 | package org.onlab.graph; |
| 17 | |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 18 | import com.google.common.testing.EqualsTester; |
| 19 | import org.junit.Test; |
| 20 | |
| 21 | import java.util.List; |
| 22 | |
| 23 | import static com.google.common.collect.ImmutableList.of; |
| 24 | import static org.junit.Assert.assertEquals; |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 25 | |
| 26 | /** |
| 27 | * Test of the default path. |
| 28 | */ |
| 29 | public class DefaultPathTest extends GraphTest { |
| 30 | |
| 31 | @Test |
| 32 | public void equality() { |
| 33 | List<TestEdge> edges = of(new TestEdge(A, B, 1), new TestEdge(B, C, 1)); |
| 34 | new EqualsTester().addEqualityGroup(new DefaultPath<>(edges, 2.0), |
| 35 | new DefaultPath<>(edges, 2.0)) |
| 36 | .addEqualityGroup(new DefaultPath<>(edges, 3.0)) |
| 37 | .testEquals(); |
| 38 | } |
| 39 | |
| 40 | @Test |
| 41 | public void basics() { |
| 42 | Path<TestVertex, TestEdge> p = new DefaultPath<>(of(new TestEdge(A, B, 1), |
| 43 | new TestEdge(B, C, 1)), 2.0); |
| 44 | validatePath(p, A, C, 2, 2.0); |
| 45 | } |
| 46 | |
| 47 | // Validates the path against expected attributes |
| 48 | protected void validatePath(Path<TestVertex, TestEdge> p, |
tom | c53fa0d | 2014-08-29 11:57:11 -0700 | [diff] [blame] | 49 | TestVertex src, TestVertex dst, |
| 50 | int length, double cost) { |
tom | 144de69 | 2014-08-29 11:38:44 -0700 | [diff] [blame] | 51 | assertEquals("incorrect path length", length, p.edges().size()); |
| 52 | assertEquals("incorrect source", src, p.src()); |
| 53 | assertEquals("incorrect destination", dst, p.dst()); |
| 54 | assertEquals("incorrect path cost", cost, p.cost(), 0.1); |
| 55 | } |
| 56 | |
| 57 | } |