blob: 891a76852897c4be209e73a204ad94e1ed5a6887 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2014-present 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() {
Andrey Komarov2398d962016-09-26 15:11:23 +030033 List<TestEdge> edges = of(new TestEdge(A, B), new TestEdge(B, C));
34 new EqualsTester().addEqualityGroup(new DefaultPath<>(edges, new TestDoubleWeight(2.0)),
35 new DefaultPath<>(edges, new TestDoubleWeight(2.0)))
36 .addEqualityGroup(new DefaultPath<>(edges, new TestDoubleWeight(3.0)))
tom144de692014-08-29 11:38:44 -070037 .testEquals();
38 }
39
40 @Test
41 public void basics() {
Andrey Komarov2398d962016-09-26 15:11:23 +030042 Path<TestVertex, TestEdge> p = new DefaultPath<>(of(new TestEdge(A, B),
43 new TestEdge(B, C)),
44 new TestDoubleWeight(2.0));
45 validatePath(p, A, C, 2, new TestDoubleWeight(2.0));
tom144de692014-08-29 11:38:44 -070046 }
47
48 // Validates the path against expected attributes
49 protected void validatePath(Path<TestVertex, TestEdge> p,
tomc53fa0d2014-08-29 11:57:11 -070050 TestVertex src, TestVertex dst,
Andrey Komarov2398d962016-09-26 15:11:23 +030051 int length, Weight cost) {
tom144de692014-08-29 11:38:44 -070052 assertEquals("incorrect path length", length, p.edges().size());
53 assertEquals("incorrect source", src, p.src());
54 assertEquals("incorrect destination", dst, p.dst());
Andrey Komarov2398d962016-09-26 15:11:23 +030055 assertEquals("incorrect path cost", cost, p.cost());
tom144de692014-08-29 11:38:44 -070056 }
57
58}