• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2014 The Guava Authors
3  *
4  * 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
7  *
8  * 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.
15  */
16 
17 package com.google.common.graph;
18 
19 import java.util.Arrays;
20 import java.util.Collection;
21 import org.junit.runner.RunWith;
22 import org.junit.runners.Parameterized;
23 import org.junit.runners.Parameterized.Parameters;
24 
25 /** Tests for a directed {@link StandardMutableGraph}. */
26 @AndroidIncompatible
27 @RunWith(Parameterized.class)
28 public final class StandardImmutableDirectedGraphTest extends AbstractStandardDirectedGraphTest {
29 
30   @Parameters(name = "allowsSelfLoops={0}")
parameters()31   public static Collection<Object[]> parameters() {
32     return Arrays.asList(new Object[][] {{false}, {true}});
33   }
34 
35   private final boolean allowsSelfLoops;
36   private ImmutableGraph.Builder<Integer> graphBuilder;
37 
StandardImmutableDirectedGraphTest(boolean allowsSelfLoops)38   public StandardImmutableDirectedGraphTest(boolean allowsSelfLoops) {
39     this.allowsSelfLoops = allowsSelfLoops;
40   }
41 
42   @Override
createGraph()43   public Graph<Integer> createGraph() {
44     graphBuilder = GraphBuilder.directed().allowsSelfLoops(allowsSelfLoops).immutable();
45     return graphBuilder.build();
46   }
47 
48   @Override
addNode(Integer n)49   final void addNode(Integer n) {
50     graphBuilder.addNode(n);
51     graph = graphBuilder.build();
52   }
53 
54   @Override
putEdge(Integer n1, Integer n2)55   final void putEdge(Integer n1, Integer n2) {
56     graphBuilder.putEdge(n1, n2);
57     graph = graphBuilder.build();
58   }
59 }
60