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 an undirected {@link StandardMutableNetwork}. */
27 @AndroidIncompatible
28 @RunWith(Parameterized.class)
29 public final class StandardMutableUndirectedNetworkTest
30     extends AbstractStandardUndirectedNetworkTest {
31 
32   @Parameters(name = "allowsSelfLoops={0}, allowsParallelEdges={1}, nodeOrder={2}, edgeOrder={3}")
parameters()33   public static Collection<Object[]> parameters() {
34     ElementOrder<?> naturalElementOrder = ElementOrder.sorted(Ordering.natural());
35 
36     return Arrays.asList(
37         new Object[][] {
38           {false, false, ElementOrder.insertion(), ElementOrder.insertion()},
39           {true, false, ElementOrder.insertion(), ElementOrder.insertion()},
40           {false, false, naturalElementOrder, naturalElementOrder},
41           {true, true, ElementOrder.insertion(), ElementOrder.insertion()},
42         });
43   }
44 
45   private final boolean allowsSelfLoops;
46   private final boolean allowsParallelEdges;
47   private final ElementOrder<Integer> nodeOrder;
48   private final ElementOrder<String> edgeOrder;
49 
StandardMutableUndirectedNetworkTest( boolean allowsSelfLoops, boolean allowsParallelEdges, ElementOrder<Integer> nodeOrder, ElementOrder<String> edgeOrder)50   public StandardMutableUndirectedNetworkTest(
51       boolean allowsSelfLoops,
52       boolean allowsParallelEdges,
53       ElementOrder<Integer> nodeOrder,
54       ElementOrder<String> edgeOrder) {
55     this.allowsSelfLoops = allowsSelfLoops;
56     this.allowsParallelEdges = allowsParallelEdges;
57     this.nodeOrder = nodeOrder;
58     this.edgeOrder = edgeOrder;
59   }
60 
61   @Override
createGraph()62   MutableNetwork<Integer, String> createGraph() {
63     return NetworkBuilder.undirected()
64         .allowsSelfLoops(allowsSelfLoops)
65         .allowsParallelEdges(allowsParallelEdges)
66         .nodeOrder(nodeOrder)
67         .edgeOrder(edgeOrder)
68         .build();
69   }
70 
71   @Override
addNode(Integer n)72   void addNode(Integer n) {
73     networkAsMutableNetwork.addNode(n);
74   }
75 
76   @Override
addEdge(Integer n1, Integer n2, String e)77   void addEdge(Integer n1, Integer n2, String e) {
78     networkAsMutableNetwork.addEdge(n1, n2, e);
79   }
80 }
81