SequenceForwardOrder { public List<Node<?,?>> putIntoForwardOrder() { assignDepth(); for( int i = 0; i < sequence.size(); i++ ) { NodeData n = sequence.get(i); if( n.depth == Integer.MAX_VALUE ) { throw new RuntimeException("Disconnected node from graph "+n.node.name); } } List<NodeData> copy = new ArrayList<>(sequence); Collections.sort(copy,new CompareWithDepth()); List<Node<?,?>> ordered = new ArrayList<>(); for (int i = 0; i < copy.size(); i++) { ordered.add( copy.get(i).node ); } return ordered; } SequenceForwardOrder(List<Node<?,?>> list ); List<Node<?,?>> putIntoForwardOrder();  }
@Test public void putIntoForwardOrder_line() { for (int length = 1; length < 5; length++) { List<Node> ordered = createLineSequence(length); List<Node> shuffled = new ArrayList<>(ordered); Collections.shuffle(shuffled, rand); SequenceForwardOrder alg = new SequenceForwardOrder((List) shuffled); List<Node<?,?>> found = alg.putIntoForwardOrder(); for (int i = 0; i < length; i++) { assertTrue(ordered.get(i)==found.get(i)); } } }
@Test public void putIntoForwardOrder_branch() { List<Node> ordered = createBranchA(); for (int trial = 0; trial < 10; trial++) { List<Node> shuffled = new ArrayList<>(ordered); Collections.shuffle(shuffled, rand); SequenceForwardOrder alg = new SequenceForwardOrder((List) shuffled); List<Node<?,?>> found = alg.putIntoForwardOrder(); for (int i = 0; i < ordered.size(); i++) { assertTrue(ordered.get(i)==found.get(i)); } } }