package com.codemelon.graph.search;

import static org.junit.Assert.*;

import java.util.HashMap;

import org.junit.After;
import org.junit.Test;

import com.codemelon.graph.graph.DiGraph;
import com.codemelon.graph.vertex.types.DfsVertex;

/**
 * @author Marshall Farrier
 * @version Nov 27, 2012
 *
 */
public class TopologicalSortTest {
	private DiGraph<DfsVertex> graph;
	
	@After
	public void tearDown() {
		graph = null;
	}

	/**
	 * Test method for {@link com.codemelon.graph.util.search.depthfirst.TopologicalSort#sort()}.
	 */
	@Test
	public void testSmallCLRSGraph() {
		HashMap<String, DfsVertex> vertices = setUpSmallCLRSGraph();
		TopologicalSort topSort = new TopologicalSort(graph);
		assertTrue("Proper precedences", topSort.showsAsInOrder(vertices.get("undershorts"), 
				vertices.get("pants")));
		assertTrue("Proper precedences", topSort.showsAsInOrder(vertices.get("socks"), 
				vertices.get("shoes")));
		assertTrue("Proper precedences", topSort.showsAsInOrder(vertices.get("pants"), 
				vertices.get("belt")));
		assertTrue("Proper precedences", topSort.showsAsInOrder(vertices.get("undershorts"), 
				vertices.get("shoes")));
		assertTrue("Proper precedences", topSort.showsAsInOrder(vertices.get("pants"), 
				vertices.get("shoes")));
		assertTrue("Proper precedences", topSort.showsAsInOrder(vertices.get("shirt"), 
				vertices.get("belt")));
		assertTrue("Proper precedences", topSort.showsAsInOrder(vertices.get("shirt"), 
				vertices.get("tie")));
		assertTrue("Proper precedences", topSort.showsAsInOrder(vertices.get("tie"), 
				vertices.get("jacket")));
	}
	/**
	 * Graph from CLRS, p. 613
	 */
	private HashMap<String, DfsVertex> setUpSmallCLRSGraph() {
		HashMap<String, DfsVertex> vertices = new HashMap<String, DfsVertex>();
		vertices.put("undershorts", new DfsVertex());
		vertices.put("pants", new DfsVertex());
		vertices.put("belt", new DfsVertex());
		vertices.put("shirt", new DfsVertex());
		vertices.put("tie", new DfsVertex());
		vertices.put("jacket", new DfsVertex());
		vertices.put("socks", new DfsVertex());
		vertices.put("shoes", new DfsVertex());
		vertices.put("watch", new DfsVertex());
		graph = new DiGraph<DfsVertex>(vertices.values());
		graph.addEdge(vertices.get("undershorts"), vertices.get("pants"));
		graph.addEdge(vertices.get("undershorts"), vertices.get("shoes"));
		graph.addEdge(vertices.get("pants"), vertices.get("belt"));
		graph.addEdge(vertices.get("pants"), vertices.get("shoes"));
		graph.addEdge(vertices.get("socks"), vertices.get("shoes"));
		graph.addEdge(vertices.get("shirt"), vertices.get("belt"));
		graph.addEdge(vertices.get("shirt"), vertices.get("tie"));
		graph.addEdge(vertices.get("belt"), vertices.get("jacket"));
		graph.addEdge(vertices.get("tie"), vertices.get("jacket"));
		return vertices;
	}
}

@@ -1,8 +1,20 @@
+/**%0A * %0A */%0A
 package 
@@ -179,22 +179,19 @@
 n.graph.
-graph.
+Old
 DiGraph;
@@ -229,17 +229,16 @@
 tex.
-types.Dfs
+Complete
 Vert
@@ -350,34 +350,26 @@
 private 
+Old
 DiGraph
-%3CDfsVertex%3E
  graph;%0A
@@ -582,35 +582,40 @@
 HashMap%3CString, 
-Dfs
+Complete
 Vertex%3E vertices
@@ -1649,35 +1649,40 @@
 HashMap%3CString, 
-Dfs
+Complete
 Vertex%3E setUpSma
@@ -1711,27 +1711,32 @@
 Map%3CString, 
-Dfs
+Complete
 Vertex%3E vert
@@ -1762,19 +1762,24 @@
 String, 
-Dfs
+Complete
 Vertex%3E(
@@ -1807,35 +1807,40 @@
 dershorts%22, new 
-Dfs
+Complete
 Vertex());%0A%09%09ver
@@ -1854,35 +1854,40 @@
 ut(%22pants%22, new 
-Dfs
+Complete
 Vertex());%0A%09%09ver
@@ -1900,35 +1900,40 @@
 put(%22belt%22, new 
-Dfs
+Complete
 Vertex());%0A%09%09ver
@@ -1947,35 +1947,40 @@
 ut(%22shirt%22, new 
-Dfs
+Complete
 Vertex());%0A%09%09ver
@@ -1996,27 +1996,32 @@
 (%22tie%22, new 
-Dfs
+Complete
 Vertex());%0A%09
@@ -2044,27 +2044,32 @@
 acket%22, new 
-Dfs
+Complete
 Vertex());%0A%09
@@ -2087,35 +2087,40 @@
 ut(%22socks%22, new 
-Dfs
+Complete
 Vertex());%0A%09%09ver
@@ -2138,27 +2138,32 @@
 shoes%22, new 
-Dfs
+Complete
 Vertex());%0A%09
@@ -2189,19 +2189,24 @@
 h%22, new 
-Dfs
+Complete
 Vertex()
@@ -2226,26 +2226,18 @@
 new 
+Old
 DiGraph
-%3CDfsVertex%3E
 (ver

Revert "Update unit tests for topological sort"