Ejemplo n.º 1
0
	def test_scc(self):
		nodes = set([1,2,3,4,5])
		edges = {1: set([2]), 2: set([3,5]), 3: set([1]), 4: set([2]), 5: set([5])}
		g = Graph(nodes, edges)

		e_sccs = set([frozenset([1,2,3]), frozenset([5])])

		self.assertEqual(GraphUtils.getSCCs(g), e_sccs)
Ejemplo n.º 2
0
	def test_utilsEdges2AdjacentList(self):

		edges = set([(1,2), (2,3), (3,4)])

		a_edges = GraphUtils.edges2adjacentList(edges)
		e_edges = {1: set([2]), 2: set([3]), 3: set([4])}

		self.assertEqual(a_edges, e_edges)
Ejemplo n.º 3
0
	def test_getRootNodes(self):

		nodes = set([1,2,3,4,5])
		edges = {1: set([2]), 2: set([3,5]), 4: set([2])}

		g = Graph(nodes, edges)

		e_nodes = set([1,4])

		self.assertEqual(GraphUtils.getRootNodes(g), e_nodes)
Ejemplo n.º 4
0
	def test_getReacheableSubgraph(self):

		nodes = set([1,2,3,4,5])
		edges = {1: set([2]), 2: set([3,5]), 3: set([1]), 4: set([2]), 5: set([5])}
		g = Graph(nodes, edges)

		e_nodes = set([1,2,3,5])
		e_edges = {1: set([2]), 2: set([3,5]), 3: set([1]), 5: set([5])}

		r_g = GraphUtils.getReacheableSubgraph(g, 1)

		self._assertGraphsEqual(r_g, Graph(e_nodes, e_edges))
Ejemplo n.º 5
0
	def test_transposeGraph(self):

		nodes = set([1,2,3,4])
		edges = {1: set([2]), 2: set([3]), 3: set([4])}

		g = Graph(nodes, edges)

		t_g = GraphUtils.transposeGraph(g)

		e_edges = {2: set([1]), 3: set([2]), 4: set([3])}

		self._assertGraphsEqual(t_g, Graph(nodes, e_edges))
Ejemplo n.º 6
0
	def test_truncateGraph(self):

		nodes = set([1,2,3,4,5])
		edges = {1: set([2]), 2: set([3,2]), 3: set([1]), 4: set([2]), 5: set([5])}
		g = Graph(nodes, edges)

		e_nodes = set([1,2,3,5])
		e_edges = {1: set([2]), 2: set([3,2]), 3: set([1]), 5: set([5])}

		t_g = GraphUtils.truncateGraph(g, [1, 5])

		self._assertGraphsEqual(t_g, Graph(e_nodes, e_edges))
Ejemplo n.º 7
0
	def test_joinGraphs(self):

		nodes = set([1,2,3])
		edges = {1: set([2]), 2: set([3]), 3: set([3])}

		g1 = Graph(nodes, edges)

		nodes = set([3,4,5])
		edges = {3: set([4]), 4: set([5]), 5: set([4])}

		g2 = Graph(nodes, edges)

		j_g = GraphUtils.joinGraphs(g1, g2)

		e_nodes = set([1,2,3,4,5])
		e_edges = {1: set([2]), 2: set([3]), 3: set([3,4]), 4: set([5]), 5: set([4])}

		self._assertGraphsEqual(j_g, Graph(e_nodes, e_edges))