### Question:
SimpleGraph extends Graph implements ISimpleGraph { @Nonnull public IMutableGraphRelation createRelation (@Nonnull final String sFromNodeID, @Nonnull final String sToNodeID) { final IMutableGraphNode aFromNode = getNodeOfID (sFromNodeID); if (aFromNode == null) throw new IllegalArgumentException ("Failed to resolve from node ID '" + sFromNodeID + "'"); final IMutableGraphNode aToNode = getNodeOfID (sToNodeID); if (aToNode == null) throw new IllegalArgumentException ("Failed to resolve to node ID '" + sToNodeID + "'"); return createRelation (aFromNode, aToNode); } SimpleGraph();  SimpleGraph(@Nonnull final IMutableGraphObjectFactory aFactory); @Nonnull IMutableGraphRelation createRelation(@Nonnull final String sFromNodeID, @Nonnull final String sToNodeID); @Nonnull IMutableGraphRelation createRelation(@Nonnull @Nonempty final String sRelationID,
                                               @Nonnull final String sFromNodeID,
                                               @Nonnull final String sToNodeID);  }### Answer:
@Test public void testCycles () { SimpleGraph sg = _buildGraph (); assertTrue (sg.isSelfContained ()); sg = new SimpleGraph (); final IMutableGraphNode n1 = sg.createNode (null); final IMutableGraphNode n2 = sg.createNode (null); sg.createRelation (n1, n2); sg.createRelation (n2, n1); assertTrue (n1.hasRelations ()); assertTrue (n1.isConnectedWith (n2)); assertTrue (n2.hasRelations ()); assertTrue (n2.isConnectedWith (n1)); assertTrue (sg.isSelfContained ()); CommonsTestHelper.testDefaultImplementationWithEqualContentObject (_buildGraph (), _buildGraph ()); CommonsTestHelper.testDefaultImplementationWithEqualContentObject (new SimpleGraph (), new SimpleGraph ()); CommonsTestHelper.testDefaultImplementationWithDifferentContentObject (_buildGraph (), new SimpleGraph ()); }
@Test public void testCycles2 () { final SimpleGraph sg = new SimpleGraph (); for (int i = 1; i <= 6; ++i) sg.createNode (Integer.toString (i)); sg.createRelation ("1", "2"); assertFalse (sg.containsCycles ()); sg.createRelation ("2", "3"); assertFalse (sg.containsCycles ()); sg.createRelation ("3", "1"); assertTrue (sg.containsCycles ()); sg.createRelation ("4", "5"); assertTrue (sg.containsCycles ()); sg.createRelation ("5", "6"); assertTrue (sg.containsCycles ()); sg.createRelation ("6", "4"); assertTrue (sg.containsCycles ()); final NonBlockingStringWriter aSW = new NonBlockingStringWriter (); sg.createIncidenceMatrix ().print (new PrintWriter (aSW), 2, 0); LOGGER.info (aSW.getAsString ()); }
@Test public void testSelfContained () { final ISimpleGraph sg = new SimpleGraph (); assertTrue (sg.isSelfContained ()); IMutableGraphNode n1 = sg.createNode ("any"); assertTrue (sg.isSelfContained ()); IMutableGraphNode n2 = new GraphNode ("other"); sg.createRelation (n1, n2); assertFalse (sg.isSelfContained ()); assertEquals (1, sg.getAllRelations ().size ()); assertTrue (sg.removeNode (n1).isChanged ()); assertFalse (sg.removeNode (n2).isChanged ()); assertFalse (sg.removeAll ().isChanged ()); n1 = new GraphNode ("any"); assertTrue (sg.isSelfContained ()); n2 = sg.createNode ("other"); sg.createRelation (n1, n2); assertFalse (sg.isSelfContained ()); }