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