• 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 static com.google.common.truth.Truth.assertThat;
20 import static org.junit.Assert.assertTrue;
21 
22 import org.junit.Test;
23 import org.junit.runner.RunWith;
24 import org.junit.runners.JUnit4;
25 
26 /**
27  * Tests for an undirected {@link ConfigurableMutableNetwork} allowing parallel edges and
28  * self-loops.
29  */
30 @RunWith(JUnit4.class)
31 public class ConfigurableUndirectedMultiNetworkTest extends ConfigurableUndirectedNetworkTest {
32   @Override
createGraph()33   public MutableNetwork<Integer, String> createGraph() {
34     return NetworkBuilder.undirected().allowsParallelEdges(true).allowsSelfLoops(true).build();
35   }
36 
37   @Test
adjacentEdges_parallelEdges()38   public void adjacentEdges_parallelEdges() {
39     addEdge(N1, N2, E12);
40     addEdge(N1, N2, E12_A);
41     addEdge(N1, N2, E12_B);
42     addEdge(N3, N4, E34);
43     assertThat(network.adjacentEdges(E12)).containsExactly(E12_A, E12_B);
44   }
45 
46   @Test
edgesConnecting_parallelEdges()47   public void edgesConnecting_parallelEdges() {
48     assertTrue(addEdge(N1, N2, E12));
49     assertTrue(addEdge(N1, N2, E12_A));
50     assertTrue(addEdge(N2, N1, E21));
51     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12, E12_A, E21);
52     assertThat(network.edgesConnecting(N2, N1)).containsExactly(E12, E12_A, E21);
53   }
54 
55   @Test
edgesConnecting_parallelSelfLoopEdges()56   public void edgesConnecting_parallelSelfLoopEdges() {
57     assertTrue(addEdge(N1, N1, E11));
58     assertTrue(addEdge(N1, N1, E11_A));
59     assertThat(network.edgesConnecting(N1, N1)).containsExactly(E11, E11_A);
60   }
61 
62   @Override
63   @Test
addEdge_parallelEdge()64   public void addEdge_parallelEdge() {
65     assertTrue(addEdge(N1, N2, E12));
66     assertTrue(addEdge(N1, N2, E12_A));
67     assertTrue(addEdge(N2, N1, E21));
68     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12, E12_A, E21);
69   }
70 
71   @Override
72   @Test
addEdge_parallelSelfLoopEdge()73   public void addEdge_parallelSelfLoopEdge() {
74     assertTrue(addEdge(N1, N1, E11));
75     assertTrue(addEdge(N1, N1, E11_A));
76     assertThat(network.edgesConnecting(N1, N1)).containsExactly(E11, E11_A);
77   }
78 
79   @Test
removeEdge_parallelEdge()80   public void removeEdge_parallelEdge() {
81     addEdge(N1, N2, E12);
82     addEdge(N1, N2, E12_A);
83     addEdge(N2, N1, E21);
84     assertTrue(network.removeEdge(E12_A));
85     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12, E21);
86   }
87 
88   @Test
removeEdge_parallelSelfLoopEdge()89   public void removeEdge_parallelSelfLoopEdge() {
90     addEdge(N1, N1, E11);
91     addEdge(N1, N1, E11_A);
92     addEdge(N1, N2, E12);
93     assertTrue(network.removeEdge(E11_A));
94     assertThat(network.edgesConnecting(N1, N1)).containsExactly(E11);
95     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12);
96     assertTrue(network.removeEdge(E11));
97     assertThat(network.edgesConnecting(N1, N1)).isEmpty();
98     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12);
99   }
100 }
101