blob: 92befbfe8fafef933ac13c1101303c64d06e528e [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07002 * Copyright 2014 Open Networking Laboratory
Thomas Vachuska24c849c2014-10-27 09:53:05 -07003 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07004 * 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 Vachuska24c849c2014-10-27 09:53:05 -07007 *
Thomas Vachuska4f1a60c2014-10-28 13:39:07 -07008 * 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 Vachuska24c849c2014-10-27 09:53:05 -070015 */
tom144de692014-08-29 11:38:44 -070016package org.onlab.graph;
17
tom144de692014-08-29 11:38:44 -070018import com.google.common.testing.EqualsTester;
19import org.junit.Test;
20
21import java.util.List;
22
23import static com.google.common.collect.ImmutableList.of;
24import static org.junit.Assert.assertEquals;
tom144de692014-08-29 11:38:44 -070025
26/**
27 * Test of the default path.
28 */
29public 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,
tomc53fa0d2014-08-29 11:57:11 -070049 TestVertex src, TestVertex dst,
50 int length, double cost) {
tom144de692014-08-29 11:38:44 -070051 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}