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 StandardMutableNetwork} allowing self-loops. */ 27 @AndroidIncompatible 28 @RunWith(Parameterized.class) 29 public class StandardMutableDirectedNetworkTest extends AbstractStandardDirectedNetworkTest { 30 31 @Parameters(name = "allowsSelfLoops={0}, allowsParallelEdges={1}, nodeOrder={2}, edgeOrder={3}") 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 public StandardMutableDirectedNetworkTest( 50 boolean allowsSelfLoops, 51 boolean allowsParallelEdges, 52 ElementOrder<Integer> nodeOrder, 53 ElementOrder<String> edgeOrder) { 54 this.allowsSelfLoops = allowsSelfLoops; 55 this.allowsParallelEdges = allowsParallelEdges; 56 this.nodeOrder = nodeOrder; 57 this.edgeOrder = edgeOrder; 58 } 59 60 @Override 61 MutableNetwork<Integer, String> createGraph() { 62 return NetworkBuilder.directed() 63 .allowsSelfLoops(allowsSelfLoops) 64 .allowsParallelEdges(allowsParallelEdges) 65 .nodeOrder(nodeOrder) 66 .edgeOrder(edgeOrder) 67 .build(); 68 } 69 70 @Override 71 void addNode(Integer n) { 72 networkAsMutableNetwork.addNode(n); 73 } 74 75 @Override 76 void addEdge(Integer n1, Integer n2, String e) { 77 networkAsMutableNetwork.addEdge(n1, n2, e); 78 } 79 } 80