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 com.google.common.collect.Ordering;
20 import java.util.Arrays;
21 import java.util.Collection;
22 import org.junit.runner.RunWith;
23 import org.junit.runners.Parameterized;
24 import org.junit.runners.Parameterized.Parameters;
25 
26 /** Tests for a directed {@link ImmutableNetwork}. */
27 @AndroidIncompatible
28 @RunWith(Parameterized.class)
29 public class StandardImmutableDirectedNetworkTest extends AbstractStandardDirectedNetworkTest {
30 
31   @Parameters(name = "allowsSelfLoops={0}, allowsParallelEdges={1}, nodeOrder={2}, edgeOrder={3}")
parameters()32   public static Collection<Object[]> parameters() {
33     ElementOrder<?> naturalElementOrder = ElementOrder.sorted(Ordering.natural());
34 
35     return Arrays.asList(
36         new Object[][] {
37           {false, false, ElementOrder.insertion(), ElementOrder.insertion()},
38           {true, false, ElementOrder.insertion(), ElementOrder.insertion()},
39           {false, false, naturalElementOrder, naturalElementOrder},
40           {true, true, ElementOrder.insertion(), ElementOrder.insertion()},
41         });
42   }
43 
44   private final boolean allowsSelfLoops;
45   private final boolean allowsParallelEdges;
46   private final ElementOrder<Integer> nodeOrder;
47   private final ElementOrder<String> edgeOrder;
48 
49   private ImmutableNetwork.Builder<Integer, String> networkBuilder;
50 
StandardImmutableDirectedNetworkTest( boolean allowsSelfLoops, boolean allowsParallelEdges, ElementOrder<Integer> nodeOrder, ElementOrder<String> edgeOrder)51   public StandardImmutableDirectedNetworkTest(
52       boolean allowsSelfLoops,
53       boolean allowsParallelEdges,
54       ElementOrder<Integer> nodeOrder,
55       ElementOrder<String> edgeOrder) {
56     this.allowsSelfLoops = allowsSelfLoops;
57     this.allowsParallelEdges = allowsParallelEdges;
58     this.nodeOrder = nodeOrder;
59     this.edgeOrder = edgeOrder;
60   }
61 
62   @Override
createGraph()63   Network<Integer, String> createGraph() {
64     networkBuilder =
65         NetworkBuilder.directed()
66             .allowsSelfLoops(allowsSelfLoops)
67             .allowsParallelEdges(allowsParallelEdges)
68             .nodeOrder(nodeOrder)
69             .edgeOrder(edgeOrder)
70             .immutable();
71 
72     return networkBuilder.build();
73   }
74 
75   @Override
addNode(Integer n)76   void addNode(Integer n) {
77     networkBuilder.addNode(n);
78     network = networkBuilder.build();
79   }
80 
81   @Override
addEdge(Integer n1, Integer n2, String e)82   void addEdge(Integer n1, Integer n2, String e) {
83     networkBuilder.addEdge(n1, n2, e);
84     network = networkBuilder.build();
85   }
86 }
87