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