blob: 833d5ca7f3090faadfbe9e76332f500066f99175 [file] [log] [blame]
Thomas Vachuska24c849c2014-10-27 09:53:05 -07001/*
2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
9 *
10 * http://www.apache.org/licenses/LICENSE-2.0
11 *
12 * Unless required by applicable law or agreed to in writing,
13 * software distributed under the License is distributed on an
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15 * KIND, either express or implied. See the License for the
16 * specific language governing permissions and limitations
17 * under the License.
18 */
tom144de692014-08-29 11:38:44 -070019package org.onlab.graph;
20
tom144de692014-08-29 11:38:44 -070021import com.google.common.testing.EqualsTester;
22import org.junit.Test;
23
24import java.util.List;
25
26import static com.google.common.collect.ImmutableList.of;
27import static org.junit.Assert.assertEquals;
tom144de692014-08-29 11:38:44 -070028
29/**
30 * Test of the default path.
31 */
32public class DefaultPathTest extends GraphTest {
33
34 @Test
35 public void equality() {
36 List<TestEdge> edges = of(new TestEdge(A, B, 1), new TestEdge(B, C, 1));
37 new EqualsTester().addEqualityGroup(new DefaultPath<>(edges, 2.0),
38 new DefaultPath<>(edges, 2.0))
39 .addEqualityGroup(new DefaultPath<>(edges, 3.0))
40 .testEquals();
41 }
42
43 @Test
44 public void basics() {
45 Path<TestVertex, TestEdge> p = new DefaultPath<>(of(new TestEdge(A, B, 1),
46 new TestEdge(B, C, 1)), 2.0);
47 validatePath(p, A, C, 2, 2.0);
48 }
49
50 // Validates the path against expected attributes
51 protected void validatePath(Path<TestVertex, TestEdge> p,
tomc53fa0d2014-08-29 11:57:11 -070052 TestVertex src, TestVertex dst,
53 int length, double cost) {
tom144de692014-08-29 11:38:44 -070054 assertEquals("incorrect path length", length, p.edges().size());
55 assertEquals("incorrect source", src, p.src());
56 assertEquals("incorrect destination", dst, p.dst());
57 assertEquals("incorrect path cost", cost, p.cost(), 0.1);
58 }
59
60}