blob: 02f79fa8be0afa4420fd121759ac9361d2d15789 [file] [log] [blame]
tom144de692014-08-29 11:38:44 -07001package org.onlab.graph;
2
tom144de692014-08-29 11:38:44 -07003import com.google.common.testing.EqualsTester;
4import org.junit.Test;
5
6import java.util.List;
7
8import static com.google.common.collect.ImmutableList.of;
9import static org.junit.Assert.assertEquals;
tom144de692014-08-29 11:38:44 -070010
11/**
12 * Test of the default path.
13 */
14public 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,
tomc53fa0d2014-08-29 11:57:11 -070034 TestVertex src, TestVertex dst,
35 int length, double cost) {
tom144de692014-08-29 11:38:44 -070036 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}