/*
 * Copyright 2016 MovingBlocks
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.terasology.utilities.collection;


import com.google.common.collect.Lists;
import org.junit.Test;

import java.util.Arrays;
import java.util.List;

import static org.junit.Assert.*;

public class DirectedAcyclicGraphTest {

    @Test
    public void addTest() {
        DirectedAcyclicGraph<String> dag = new DirectedAcyclicGraph<>();

        dag.addVertex("A");
        dag.addVertex("B");
        dag.addVertex("C");
    }

    @Test
    public void addPrecessorTest() {
        DirectedAcyclicGraph<String> dag = new DirectedAcyclicGraph<>();

        assertTrue(dag.addVertex("A"));
        assertTrue(dag.addVertex("B"));
        assertTrue(dag.addVertex("C"));

        dag.addEdge("B", "A");
        dag.addEdge("C", "A");
    }

    @Test
    public void addPrecessorTest2() {
        DirectedAcyclicGraph<String> dag = new DirectedAcyclicGraph<>();

        assertTrue(dag.addVertex("A"));
        assertTrue(dag.addVertex("B"));
        assertTrue(dag.addVertex("C"));

        dag.addEdge("A", "B");
        dag.addEdge("A", "C");
    }

    @Test(expected = IllegalArgumentException.class)
    public void addUnknownEdgeTest() {
        DirectedAcyclicGraph<String> dag = new DirectedAcyclicGraph<>();

        dag.addEdge("C", "A");
    }


    @Test
    public void cyclicCheckTest() {
        DirectedAcyclicGraph<String> dag = new DirectedAcyclicGraph<>();

        dag.addVertex("A");
        dag.addVertex("B");

        assertTrue(dag.addEdge("A", "B"));
        assertFalse(dag.addEdge("B", "A"));
    }

    @Test
    public void topologicalOrderTest() {
        DirectedAcyclicGraph<Integer> dag = new DirectedAcyclicGraph<>();
        List<Integer> list = Lists.newArrayList(1, 2, 3, 4);
        for (Integer i : list) {
            assertTrue(dag.addVertex(i));
        }

        assertTrue(dag.addEdge(1, 2));
        assertTrue(dag.addEdge(2, 3));
        assertTrue(dag.addEdge(3, 4));
        assertTrue(dag.addEdge(1, 3));
        assertTrue(dag.addEdge(1, 4));

        List<Integer> order = dag.getTopologicalOrder();

        assertEquals(Arrays.toString(list.toArray()), Arrays.toString(order.toArray()));
    }

    @Test
    public void topologicalOrderComplexCyclicTest() {
        DirectedAcyclicGraph<Integer> dag = new DirectedAcyclicGraph<>();
        List<Integer> list = Lists.newArrayList(1, 2, 3, 4);
        for (Integer i : list) {
            assertTrue(dag.addVertex(i));
        }

        assertTrue(dag.addEdge(1, 2));
        assertTrue(dag.addEdge(2, 3));
        assertTrue(dag.addEdge(3, 4));
        assertTrue(dag.addEdge(1, 3));
        assertTrue(dag.addEdge(1, 4));
        assertFalse(dag.addEdge(4, 2));

        List<Integer> order = dag.getTopologicalOrder();

        assertNotNull(order);
    }

}
@@ -636,17 +636,16 @@
 ction;%0A%0A
-%0A
 import c
@@ -780,17 +780,161 @@
 .Assert.
-*
+assertEquals;%0Aimport static org.junit.Assert.assertNotNull;%0Aimport static org.junit.Assert.assertTrue;%0Aimport static org.junit.Assert.assertFalse
 ;%0A%0Apubli
@@ -1088,38 +1088,36 @@
 %0A        dag.add
-Vertex
+Node
 (%22A%22);%0A        d
@@ -1118,30 +1118,28 @@
      dag.add
-Vertex
+Node
 (%22B%22);%0A     
@@ -1144,30 +1144,28 @@
      dag.add
-Vertex
+Node
 (%22C%22);%0A    %7D
@@ -1305,38 +1305,36 @@
 sertTrue(dag.add
-Vertex
+Node
 (%22A%22));%0A        
@@ -1343,38 +1343,36 @@
 sertTrue(dag.add
-Vertex
+Node
 (%22B%22));%0A        
@@ -1381,38 +1381,36 @@
 sertTrue(dag.add
-Vertex
+Node
 (%22C%22));%0A%0A       
@@ -1615,30 +1615,28 @@
 True(dag.add
-Vertex
+Node
 (%22A%22));%0A    
@@ -1653,30 +1653,28 @@
 True(dag.add
-Vertex
+Node
 (%22B%22));%0A    
@@ -1695,22 +1695,20 @@
 (dag.add
-Vertex
+Node
 (%22C%22));%0A
@@ -1981,17 +1981,16 @@
 %0A    %7D%0A%0A
-%0A
     @Tes
@@ -2116,22 +2116,20 @@
  dag.add
-Vertex
+Node
 (%22A%22);%0A 
@@ -2142,22 +2142,20 @@
  dag.add
-Vertex
+Node
 (%22B%22);%0A%0A
@@ -2489,38 +2489,36 @@
 sertTrue(dag.add
-Vertex
+Node
 (i));%0A        %7D%0A
@@ -3134,14 +3134,12 @@
 .add
-Vertex
+Node
 (i))
@@ -3482,9 +3482,10 @@
 %0A    %7D%0A%0A
-
 %7D
+%0A

Refactor wild card import