blob: dbdf57fd78d78b35173dfabb1194403eff0a0582 [file] [log] [blame]
tom144de692014-08-29 11:38:44 -07001package org.onlab.graph;
2
3import com.google.common.collect.ImmutableList;
4import com.google.common.testing.EqualsTester;
5import org.junit.Test;
6
7import java.util.List;
8
9import static com.google.common.collect.ImmutableList.of;
10import static org.junit.Assert.assertEquals;
11import static org.junit.Assert.assertNull;
12
13/**
14 * Test of the default path.
15 */
16public 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}