• 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.graph.GraphConstants.ENDPOINTS_MISMATCH;
20 import static com.google.common.truth.Truth.assertThat;
21 import static com.google.common.truth.TruthJUnit.assume;
22 import static org.junit.Assert.assertThrows;
23 import static org.junit.Assert.assertTrue;
24 import static org.junit.Assert.fail;
25 
26 import com.google.common.collect.ImmutableSet;
27 import com.google.common.testing.EqualsTester;
28 import java.util.Set;
29 import org.junit.After;
30 import org.junit.Test;
31 
32 /**
33  * Abstract base class for testing undirected {@link Network} implementations defined in this
34  * package.
35  */
36 public abstract class AbstractStandardUndirectedNetworkTest extends AbstractNetworkTest {
37   private static final EndpointPair<Integer> ENDPOINTS_N1N2 = EndpointPair.ordered(N1, N2);
38   private static final EndpointPair<Integer> ENDPOINTS_N2N1 = EndpointPair.ordered(N2, N1);
39 
40   @After
validateUndirectedEdges()41   public void validateUndirectedEdges() {
42     for (Integer node : network.nodes()) {
43       new EqualsTester()
44           .addEqualityGroup(
45               network.inEdges(node), network.outEdges(node), network.incidentEdges(node))
46           .testEquals();
47       new EqualsTester()
48           .addEqualityGroup(
49               network.predecessors(node), network.successors(node), network.adjacentNodes(node))
50           .testEquals();
51 
52       for (Integer adjacentNode : network.adjacentNodes(node)) {
53         assertThat(network.edgesConnecting(node, adjacentNode))
54             .containsExactlyElementsIn(network.edgesConnecting(adjacentNode, node));
55       }
56     }
57   }
58 
59   @Override
60   @Test
nodes_checkReturnedSetMutability()61   public void nodes_checkReturnedSetMutability() {
62     Set<Integer> nodes = network.nodes();
63     UnsupportedOperationException e =
64         assertThrows(UnsupportedOperationException.class, () -> nodes.add(N2));
65     addNode(N1);
66     assertThat(network.nodes()).containsExactlyElementsIn(nodes);
67   }
68 
69   @Override
70   @Test
edges_checkReturnedSetMutability()71   public void edges_checkReturnedSetMutability() {
72     Set<String> edges = network.edges();
73     UnsupportedOperationException e =
74         assertThrows(UnsupportedOperationException.class, () -> edges.add(E12));
75     addEdge(N1, N2, E12);
76     assertThat(network.edges()).containsExactlyElementsIn(edges);
77   }
78 
79   @Override
80   @Test
incidentEdges_checkReturnedSetMutability()81   public void incidentEdges_checkReturnedSetMutability() {
82     addNode(N1);
83     Set<String> incidentEdges = network.incidentEdges(N1);
84     UnsupportedOperationException e =
85         assertThrows(UnsupportedOperationException.class, () -> incidentEdges.add(E12));
86     addEdge(N1, N2, E12);
87     assertThat(network.incidentEdges(N1)).containsExactlyElementsIn(incidentEdges);
88   }
89 
90   @Override
91   @Test
adjacentNodes_checkReturnedSetMutability()92   public void adjacentNodes_checkReturnedSetMutability() {
93     addNode(N1);
94     Set<Integer> adjacentNodes = network.adjacentNodes(N1);
95     UnsupportedOperationException e =
96         assertThrows(UnsupportedOperationException.class, () -> adjacentNodes.add(N2));
97     addEdge(N1, N2, E12);
98     assertThat(network.adjacentNodes(N1)).containsExactlyElementsIn(adjacentNodes);
99   }
100 
101   @Override
adjacentEdges_checkReturnedSetMutability()102   public void adjacentEdges_checkReturnedSetMutability() {
103     addEdge(N1, N2, E12);
104     Set<String> adjacentEdges = network.adjacentEdges(E12);
105     try {
106       adjacentEdges.add(E23);
107       fail(ERROR_MODIFIABLE_COLLECTION);
108     } catch (UnsupportedOperationException e) {
109       addEdge(N2, N3, E23);
110       assertThat(network.adjacentEdges(E12)).containsExactlyElementsIn(adjacentEdges);
111     }
112   }
113 
114   @Override
115   @Test
edgesConnecting_checkReturnedSetMutability()116   public void edgesConnecting_checkReturnedSetMutability() {
117     addNode(N1);
118     addNode(N2);
119     Set<String> edgesConnecting = network.edgesConnecting(N1, N2);
120     UnsupportedOperationException e =
121         assertThrows(UnsupportedOperationException.class, () -> edgesConnecting.add(E23));
122     addEdge(N1, N2, E12);
123     assertThat(network.edgesConnecting(N1, N2)).containsExactlyElementsIn(edgesConnecting);
124   }
125 
126   @Override
127   @Test
inEdges_checkReturnedSetMutability()128   public void inEdges_checkReturnedSetMutability() {
129     addNode(N2);
130     Set<String> inEdges = network.inEdges(N2);
131     UnsupportedOperationException e =
132         assertThrows(UnsupportedOperationException.class, () -> inEdges.add(E12));
133     addEdge(N1, N2, E12);
134     assertThat(network.inEdges(N2)).containsExactlyElementsIn(inEdges);
135   }
136 
137   @Override
138   @Test
outEdges_checkReturnedSetMutability()139   public void outEdges_checkReturnedSetMutability() {
140     addNode(N1);
141     Set<String> outEdges = network.outEdges(N1);
142     UnsupportedOperationException e =
143         assertThrows(UnsupportedOperationException.class, () -> outEdges.add(E12));
144     addEdge(N1, N2, E12);
145     assertThat(network.outEdges(N1)).containsExactlyElementsIn(outEdges);
146   }
147 
148   @Override
149   @Test
predecessors_checkReturnedSetMutability()150   public void predecessors_checkReturnedSetMutability() {
151     addNode(N2);
152     Set<Integer> predecessors = network.predecessors(N2);
153     UnsupportedOperationException e =
154         assertThrows(UnsupportedOperationException.class, () -> predecessors.add(N1));
155     addEdge(N1, N2, E12);
156     assertThat(network.predecessors(N2)).containsExactlyElementsIn(predecessors);
157   }
158 
159   @Override
160   @Test
successors_checkReturnedSetMutability()161   public void successors_checkReturnedSetMutability() {
162     addNode(N1);
163     Set<Integer> successors = network.successors(N1);
164     UnsupportedOperationException e =
165         assertThrows(UnsupportedOperationException.class, () -> successors.add(N2));
166     addEdge(N1, N2, E12);
167     assertThat(network.successors(N1)).containsExactlyElementsIn(successors);
168   }
169 
170   @Test
edges_containsOrderMismatch()171   public void edges_containsOrderMismatch() {
172     addEdge(N1, N2, E12);
173     assertThat(network.asGraph().edges()).doesNotContain(ENDPOINTS_N2N1);
174     assertThat(network.asGraph().edges()).doesNotContain(ENDPOINTS_N1N2);
175   }
176 
177   @Test
edgesConnecting_orderMismatch()178   public void edgesConnecting_orderMismatch() {
179     addEdge(N1, N2, E12);
180     IllegalArgumentException e =
181         assertThrows(
182             IllegalArgumentException.class,
183             () -> {
184               Set<String> unused = network.edgesConnecting(ENDPOINTS_N1N2);
185             });
186     assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
187   }
188 
189   @Test
edgeConnectingOrNull_orderMismatch()190   public void edgeConnectingOrNull_orderMismatch() {
191     addEdge(N1, N2, E12);
192     IllegalArgumentException e =
193         assertThrows(
194             IllegalArgumentException.class,
195             () -> {
196               String unused = network.edgeConnectingOrNull(ENDPOINTS_N1N2);
197             });
198     assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
199   }
200 
201   @Test
edgesConnecting_oneEdge()202   public void edgesConnecting_oneEdge() {
203     addEdge(N1, N2, E12);
204     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12);
205     assertThat(network.edgesConnecting(N2, N1)).containsExactly(E12);
206   }
207 
208   @Test
inEdges_oneEdge()209   public void inEdges_oneEdge() {
210     addEdge(N1, N2, E12);
211     assertThat(network.inEdges(N2)).containsExactly(E12);
212     assertThat(network.inEdges(N1)).containsExactly(E12);
213   }
214 
215   @Test
outEdges_oneEdge()216   public void outEdges_oneEdge() {
217     addEdge(N1, N2, E12);
218     assertThat(network.outEdges(N2)).containsExactly(E12);
219     assertThat(network.outEdges(N1)).containsExactly(E12);
220   }
221 
222   @Test
predecessors_oneEdge()223   public void predecessors_oneEdge() {
224     addEdge(N1, N2, E12);
225     assertThat(network.predecessors(N2)).containsExactly(N1);
226     assertThat(network.predecessors(N1)).containsExactly(N2);
227   }
228 
229   @Test
successors_oneEdge()230   public void successors_oneEdge() {
231     addEdge(N1, N2, E12);
232     assertThat(network.successors(N1)).containsExactly(N2);
233     assertThat(network.successors(N2)).containsExactly(N1);
234   }
235 
236   @Test
inDegree_oneEdge()237   public void inDegree_oneEdge() {
238     addEdge(N1, N2, E12);
239     assertThat(network.inDegree(N2)).isEqualTo(1);
240     assertThat(network.inDegree(N1)).isEqualTo(1);
241   }
242 
243   @Test
outDegree_oneEdge()244   public void outDegree_oneEdge() {
245     addEdge(N1, N2, E12);
246     assertThat(network.outDegree(N1)).isEqualTo(1);
247     assertThat(network.outDegree(N2)).isEqualTo(1);
248   }
249 
250   @Test
edges_selfLoop()251   public void edges_selfLoop() {
252     assume().that(network.allowsSelfLoops()).isTrue();
253 
254     addEdge(N1, N1, E11);
255     assertThat(network.edges()).containsExactly(E11);
256   }
257 
258   @Test
incidentEdges_selfLoop()259   public void incidentEdges_selfLoop() {
260     assume().that(network.allowsSelfLoops()).isTrue();
261 
262     addEdge(N1, N1, E11);
263     assertThat(network.incidentEdges(N1)).containsExactly(E11);
264   }
265 
266   @Test
incidentNodes_selfLoop()267   public void incidentNodes_selfLoop() {
268     assume().that(network.allowsSelfLoops()).isTrue();
269 
270     addEdge(N1, N1, E11);
271     assertThat(network.incidentNodes(E11).nodeU()).isEqualTo(N1);
272     assertThat(network.incidentNodes(E11).nodeV()).isEqualTo(N1);
273   }
274 
275   @Test
adjacentNodes_selfLoop()276   public void adjacentNodes_selfLoop() {
277     assume().that(network.allowsSelfLoops()).isTrue();
278 
279     addEdge(N1, N1, E11);
280     addEdge(N1, N2, E12);
281     assertThat(network.adjacentNodes(N1)).containsExactly(N1, N2);
282   }
283 
284   @Test
adjacentEdges_selfLoop()285   public void adjacentEdges_selfLoop() {
286     assume().that(network.allowsSelfLoops()).isTrue();
287 
288     addEdge(N1, N1, E11);
289     addEdge(N1, N2, E12);
290     assertThat(network.adjacentEdges(E11)).containsExactly(E12);
291   }
292 
293   @Test
edgesConnecting_selfLoop()294   public void edgesConnecting_selfLoop() {
295     assume().that(network.allowsSelfLoops()).isTrue();
296 
297     addEdge(N1, N1, E11);
298     assertThat(network.edgesConnecting(N1, N1)).containsExactly(E11);
299     addEdge(N1, N2, E12);
300     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12);
301     assertThat(network.edgesConnecting(N2, N1)).containsExactly(E12);
302     assertThat(network.edgesConnecting(N1, N1)).containsExactly(E11);
303   }
304 
305   @Test
inEdges_selfLoop()306   public void inEdges_selfLoop() {
307     assume().that(network.allowsSelfLoops()).isTrue();
308 
309     addEdge(N1, N1, E11);
310     assertThat(network.inEdges(N1)).containsExactly(E11);
311     addEdge(N1, N2, E12);
312     assertThat(network.inEdges(N1)).containsExactly(E11, E12);
313   }
314 
315   @Test
outEdges_selfLoop()316   public void outEdges_selfLoop() {
317     assume().that(network.allowsSelfLoops()).isTrue();
318 
319     addEdge(N1, N1, E11);
320     assertThat(network.outEdges(N1)).containsExactly(E11);
321     addEdge(N2, N1, E12);
322     assertThat(network.outEdges(N1)).containsExactly(E11, E12);
323   }
324 
325   @Test
predecessors_selfLoop()326   public void predecessors_selfLoop() {
327     assume().that(network.allowsSelfLoops()).isTrue();
328 
329     addEdge(N1, N1, E11);
330     assertThat(network.predecessors(N1)).containsExactly(N1);
331     addEdge(N1, N2, E12);
332     assertThat(network.predecessors(N1)).containsExactly(N1, N2);
333   }
334 
335   @Test
successors_selfLoop()336   public void successors_selfLoop() {
337     assume().that(network.allowsSelfLoops()).isTrue();
338 
339     addEdge(N1, N1, E11);
340     assertThat(network.successors(N1)).containsExactly(N1);
341     addEdge(N2, N1, E12);
342     assertThat(network.successors(N1)).containsExactly(N1, N2);
343   }
344 
345   @Test
degree_selfLoop()346   public void degree_selfLoop() {
347     assume().that(network.allowsSelfLoops()).isTrue();
348 
349     addEdge(N1, N1, E11);
350     assertThat(network.degree(N1)).isEqualTo(2);
351     addEdge(N1, N2, E12);
352     assertThat(network.degree(N1)).isEqualTo(3);
353   }
354 
355   @Test
inDegree_selfLoop()356   public void inDegree_selfLoop() {
357     assume().that(network.allowsSelfLoops()).isTrue();
358 
359     addEdge(N1, N1, E11);
360     assertThat(network.inDegree(N1)).isEqualTo(2);
361     addEdge(N1, N2, E12);
362     assertThat(network.inDegree(N1)).isEqualTo(3);
363   }
364 
365   @Test
outDegree_selfLoop()366   public void outDegree_selfLoop() {
367     assume().that(network.allowsSelfLoops()).isTrue();
368 
369     addEdge(N1, N1, E11);
370     assertThat(network.outDegree(N1)).isEqualTo(2);
371     addEdge(N2, N1, E12);
372     assertThat(network.outDegree(N1)).isEqualTo(3);
373   }
374 
375   // Element Mutation
376 
377   @Test
addEdge_existingNodes()378   public void addEdge_existingNodes() {
379     assume().that(graphIsMutable()).isTrue();
380 
381     // Adding nodes initially for safety (insulating from possible future
382     // modifications to proxy methods)
383     addNode(N1);
384     addNode(N2);
385     assertThat(networkAsMutableNetwork.addEdge(N1, N2, E12)).isTrue();
386     assertThat(network.edges()).contains(E12);
387     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12);
388     assertThat(network.edgesConnecting(N2, N1)).containsExactly(E12);
389   }
390 
391   @Test
addEdge_existingEdgeBetweenSameNodes()392   public void addEdge_existingEdgeBetweenSameNodes() {
393     assume().that(graphIsMutable()).isTrue();
394 
395     assertThat(networkAsMutableNetwork.addEdge(N1, N2, E12)).isTrue();
396     ImmutableSet<String> edges = ImmutableSet.copyOf(network.edges());
397     assertThat(networkAsMutableNetwork.addEdge(N1, N2, E12)).isFalse();
398     assertThat(network.edges()).containsExactlyElementsIn(edges);
399     assertThat(networkAsMutableNetwork.addEdge(N2, N1, E12)).isFalse();
400     assertThat(network.edges()).containsExactlyElementsIn(edges);
401   }
402 
403   @Test
addEdge_existingEdgeBetweenDifferentNodes()404   public void addEdge_existingEdgeBetweenDifferentNodes() {
405     assume().that(graphIsMutable()).isTrue();
406 
407     addEdge(N1, N2, E12);
408     IllegalArgumentException e =
409         assertThrows(
410             IllegalArgumentException.class, () -> networkAsMutableNetwork.addEdge(N4, N5, E12));
411     assertThat(e).hasMessageThat().contains(ERROR_REUSE_EDGE);
412   }
413 
414   @Test
addEdge_parallelEdge_notAllowed()415   public void addEdge_parallelEdge_notAllowed() {
416     assume().that(graphIsMutable()).isTrue();
417     assume().that(network.allowsParallelEdges()).isFalse();
418 
419     addEdge(N1, N2, E12);
420     IllegalArgumentException e =
421         assertThrows(
422             IllegalArgumentException.class,
423             () -> networkAsMutableNetwork.addEdge(N1, N2, EDGE_NOT_IN_GRAPH));
424     assertThat(e).hasMessageThat().contains(ERROR_PARALLEL_EDGE);
425     e =
426         assertThrows(
427             IllegalArgumentException.class,
428             () -> networkAsMutableNetwork.addEdge(N2, N1, EDGE_NOT_IN_GRAPH));
429     assertThat(e).hasMessageThat().contains(ERROR_PARALLEL_EDGE);
430   }
431 
432   @Test
addEdge_parallelEdge_allowsParallelEdges()433   public void addEdge_parallelEdge_allowsParallelEdges() {
434     assume().that(graphIsMutable()).isTrue();
435     assume().that(network.allowsParallelEdges()).isTrue();
436 
437     assertTrue(networkAsMutableNetwork.addEdge(N1, N2, E12));
438     assertTrue(networkAsMutableNetwork.addEdge(N2, N1, E21));
439     assertTrue(networkAsMutableNetwork.addEdge(N1, N2, E12_A));
440     assertThat(network.edgesConnecting(N1, N2)).containsExactly(E12, E12_A, E21);
441   }
442 
443   @Test
addEdge_orderMismatch()444   public void addEdge_orderMismatch() {
445     assume().that(graphIsMutable()).isTrue();
446 
447     EndpointPair<Integer> endpoints = EndpointPair.ordered(N1, N2);
448     IllegalArgumentException e =
449         assertThrows(
450             IllegalArgumentException.class, () -> networkAsMutableNetwork.addEdge(endpoints, E12));
451     assertThat(e).hasMessageThat().contains(ENDPOINTS_MISMATCH);
452   }
453 
454   @Test
addEdge_selfLoop_notAllowed()455   public void addEdge_selfLoop_notAllowed() {
456     assume().that(graphIsMutable()).isTrue();
457     assume().that(network.allowsSelfLoops()).isFalse();
458 
459     IllegalArgumentException e =
460         assertThrows(
461             IllegalArgumentException.class, () -> networkAsMutableNetwork.addEdge(N1, N1, E11));
462     assertThat(e).hasMessageThat().contains(ERROR_SELF_LOOP);
463   }
464 
465   /**
466    * This test checks an implementation dependent feature. It tests that the method {@code addEdge}
467    * will silently add the missing nodes to the graph, then add the edge connecting them. We are not
468    * using the proxy methods here as we want to test {@code addEdge} when the end-points are not
469    * elements of the graph.
470    */
471   @Test
addEdge_nodesNotInGraph()472   public void addEdge_nodesNotInGraph() {
473     assume().that(graphIsMutable()).isTrue();
474 
475     networkAsMutableNetwork.addNode(N1);
476     assertTrue(networkAsMutableNetwork.addEdge(N1, N5, E15));
477     assertTrue(networkAsMutableNetwork.addEdge(N4, N1, E41));
478     assertTrue(networkAsMutableNetwork.addEdge(N2, N3, E23));
479     assertThat(network.nodes()).containsExactly(N1, N5, N4, N2, N3);
480     assertThat(network.edges()).containsExactly(E15, E41, E23);
481     assertThat(network.edgesConnecting(N1, N5)).containsExactly(E15);
482     assertThat(network.edgesConnecting(N4, N1)).containsExactly(E41);
483     assertThat(network.edgesConnecting(N2, N3)).containsExactly(E23);
484     assertThat(network.edgesConnecting(N3, N2)).containsExactly(E23);
485   }
486 
487   @Test
addEdge_selfLoop()488   public void addEdge_selfLoop() {
489     assume().that(graphIsMutable()).isTrue();
490     assume().that(network.allowsSelfLoops()).isTrue();
491 
492     assertThat(networkAsMutableNetwork.addEdge(N1, N1, E11)).isTrue();
493     assertThat(network.edges()).contains(E11);
494     assertThat(network.edgesConnecting(N1, N1)).containsExactly(E11);
495   }
496 
497   @Test
addEdge_existingSelfLoopEdgeBetweenSameNodes()498   public void addEdge_existingSelfLoopEdgeBetweenSameNodes() {
499     assume().that(graphIsMutable()).isTrue();
500     assume().that(network.allowsSelfLoops()).isTrue();
501 
502     addEdge(N1, N1, E11);
503     ImmutableSet<String> edges = ImmutableSet.copyOf(network.edges());
504     assertThat(networkAsMutableNetwork.addEdge(N1, N1, E11)).isFalse();
505     assertThat(network.edges()).containsExactlyElementsIn(edges);
506   }
507 
508   @Test
addEdge_existingEdgeBetweenDifferentNodes_selfLoops()509   public void addEdge_existingEdgeBetweenDifferentNodes_selfLoops() {
510     assume().that(graphIsMutable()).isTrue();
511     assume().that(network.allowsSelfLoops()).isTrue();
512 
513     addEdge(N1, N1, E11);
514     IllegalArgumentException e =
515         assertThrows(
516             IllegalArgumentException.class, () -> networkAsMutableNetwork.addEdge(N1, N2, E11));
517     assertThat(e).hasMessageThat().contains(ERROR_REUSE_EDGE);
518     e =
519         assertThrows(
520             IllegalArgumentException.class, () -> networkAsMutableNetwork.addEdge(N2, N2, E11));
521     assertThat(e).hasMessageThat().contains(ERROR_REUSE_EDGE);
522     addEdge(N1, N2, E12);
523     e =
524         assertThrows(
525             IllegalArgumentException.class, () -> networkAsMutableNetwork.addEdge(N1, N1, E12));
526     assertThat(e).hasMessageThat().contains(ERROR_REUSE_EDGE);
527   }
528 
529   @Test
addEdge_parallelSelfLoopEdge_notAllowed()530   public void addEdge_parallelSelfLoopEdge_notAllowed() {
531     assume().that(graphIsMutable()).isTrue();
532     assume().that(network.allowsSelfLoops()).isTrue();
533     assume().that(network.allowsParallelEdges()).isFalse();
534 
535     addEdge(N1, N1, E11);
536     IllegalArgumentException e =
537         assertThrows(
538             IllegalArgumentException.class,
539             () -> networkAsMutableNetwork.addEdge(N1, N1, EDGE_NOT_IN_GRAPH));
540     assertThat(e).hasMessageThat().contains(ERROR_PARALLEL_EDGE);
541   }
542 
543   @Test
addEdge_parallelSelfLoopEdge_allowsParallelEdges()544   public void addEdge_parallelSelfLoopEdge_allowsParallelEdges() {
545     assume().that(graphIsMutable()).isTrue();
546     assume().that(network.allowsSelfLoops()).isTrue();
547     assume().that(network.allowsParallelEdges()).isTrue();
548 
549     assertTrue(networkAsMutableNetwork.addEdge(N1, N1, E11));
550     assertTrue(networkAsMutableNetwork.addEdge(N1, N1, E11_A));
551     assertThat(network.edgesConnecting(N1, N1)).containsExactly(E11, E11_A);
552   }
553 
554   @Test
removeNode_existingNodeWithSelfLoopEdge()555   public void removeNode_existingNodeWithSelfLoopEdge() {
556     assume().that(graphIsMutable()).isTrue();
557     assume().that(network.allowsSelfLoops()).isTrue();
558 
559     addNode(N1);
560     addEdge(N1, N1, E11);
561     assertThat(networkAsMutableNetwork.removeNode(N1)).isTrue();
562     assertThat(network.nodes()).isEmpty();
563     assertThat(network.edges()).doesNotContain(E11);
564   }
565 
566   @Test
removeEdge_existingSelfLoopEdge()567   public void removeEdge_existingSelfLoopEdge() {
568     assume().that(graphIsMutable()).isTrue();
569     assume().that(network.allowsSelfLoops()).isTrue();
570 
571     addEdge(N1, N1, E11);
572     assertThat(networkAsMutableNetwork.removeEdge(E11)).isTrue();
573     assertThat(network.edges()).doesNotContain(E11);
574     assertThat(network.edgesConnecting(N1, N1)).isEmpty();
575   }
576 }
577