blob: d860928cd1dba0f1ce7d3ae28ced66385b6dc65f [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 */
tome3489412014-08-29 02:30:38 -070016package org.onlab.graph;
17
tome3489412014-08-29 02:30:38 -070018import java.util.Set;
19
tom144de692014-08-29 11:38:44 -070020import static com.google.common.collect.ImmutableSet.of;
21
tome3489412014-08-29 02:30:38 -070022/**
23 * Base class for various graph-related tests.
24 */
25public class GraphTest {
26
27 static final TestVertex A = new TestVertex("A");
28 static final TestVertex B = new TestVertex("B");
29 static final TestVertex C = new TestVertex("C");
30 static final TestVertex D = new TestVertex("D");
31 static final TestVertex E = new TestVertex("E");
32 static final TestVertex F = new TestVertex("F");
33 static final TestVertex G = new TestVertex("G");
34 static final TestVertex H = new TestVertex("H");
tom2e1f0712014-08-29 13:32:00 -070035 static final TestVertex Z = new TestVertex("Z");
tome3489412014-08-29 02:30:38 -070036
Andrey Komarov2398d962016-09-26 15:11:23 +030037 static final TestDoubleWeight ZW = new TestDoubleWeight(0);
38 static final TestDoubleWeight NW5 = new TestDoubleWeight(-5);
39 static final TestDoubleWeight NW2 = new TestDoubleWeight(-2);
40 static final TestDoubleWeight NW1 = new TestDoubleWeight(-1);
41 static final TestDoubleWeight W1 = new TestDoubleWeight(1);
42 static final TestDoubleWeight W2 = new TestDoubleWeight(2);
43 static final TestDoubleWeight W3 = new TestDoubleWeight(3);
44 static final TestDoubleWeight W4 = new TestDoubleWeight(4);
45 static final TestDoubleWeight W5 = new TestDoubleWeight(5);
46
tom0633d682014-09-10 12:10:03 -070047 protected Graph<TestVertex, TestEdge> graph;
tome3489412014-08-29 02:30:38 -070048
Andrey Komarov2398d962016-09-26 15:11:23 +030049 protected EdgeWeigher<TestVertex, TestEdge> weigher =
50 new EdgeWeigher<TestVertex, TestEdge>() {
tomc53fa0d2014-08-29 11:57:11 -070051 @Override
Andrey Komarov2398d962016-09-26 15:11:23 +030052 public Weight weight(TestEdge edge) {
tomc53fa0d2014-08-29 11:57:11 -070053 return edge.weight();
54 }
Andrey Komarov2398d962016-09-26 15:11:23 +030055
56 @Override
57 public Weight getInitialWeight() {
58 return ZW;
59 }
60
61 @Override
62 public Weight getNonViableWeight() {
63 return TestDoubleWeight.NON_VIABLE_WEIGHT;
64 }
tomc53fa0d2014-08-29 11:57:11 -070065 };
tome3489412014-08-29 02:30:38 -070066
67 protected void printPaths(Set<Path<TestVertex, TestEdge>> paths) {
68 for (Path p : paths) {
69 System.out.println(p);
70 }
71 }
72
tom0633d682014-09-10 12:10:03 -070073 protected Set<TestVertex> vertexes() {
tom144de692014-08-29 11:38:44 -070074 return of(A, B, C, D, E, F, G, H);
tome3489412014-08-29 02:30:38 -070075 }
76
77 protected Set<TestEdge> edges() {
Andrey Komarov2398d962016-09-26 15:11:23 +030078 return of(new TestEdge(A, B, W1),
79 new TestEdge(A, C, W3),
80 new TestEdge(B, D, W2),
81 new TestEdge(B, C, W1),
82 new TestEdge(B, E, W4),
83 new TestEdge(C, E, W1),
84 new TestEdge(D, H, W5),
85 new TestEdge(D, E, W1),
86 new TestEdge(E, F, W1),
87 new TestEdge(F, D, W1),
88 new TestEdge(F, G, W1),
89 new TestEdge(F, H, W1));
tome3489412014-08-29 02:30:38 -070090 }
91
92}