public void testThreeCycle() { vertexes.add(vertex1); vertexes.add(vertex2); vertexes.add(vertex3); vertex3.addEdge(vertex2); vertex2.addEdge(vertex3); vertex1.addEdge(vertex1); TopologicalSorter<DefaultVertex> sorter = new TopologicalSorter<DefaultVertex>(vertexes); assertEquals("1", sorter.findCycle().toString()); assertEquals("2, 3", sorter.findCycle(vertex2).toString()); List<DefaultVertex> result = sorter.sort(); assertEquals(3, result.size()); }
public void testMinimalCycleReturned() { vertexes.add(vertex1); vertexes.add(vertex2); vertexes.add(vertex3); vertex1.addEdge(vertex2); vertex3.addEdge(vertex2); vertex2.addEdge(vertex3); TopologicalSorter<DefaultVertex> sorter = new TopologicalSorter<DefaultVertex>(vertexes); assertEquals("2, 3", sorter.findCycle().toString()); }
public void testPickThenCycle() { vertexes.add(vertex1); vertexes.add(vertex2); vertexes.add(vertex3); vertex3.addEdge(vertex2); vertex2.addEdge(vertex3); TopologicalSorter<DefaultVertex> sorter = new TopologicalSorter<DefaultVertex>(vertexes); sorter.setBreakOnCycle(true); sorter.sort(); assertEquals("2, 3", sorter.findCycle().toString()); }