Exemple #1
1
	def test_transpose_matrix(self):
		vertices = [self.vertex, self.vertex2, self.vertex3]
		edges = [self.edge, self.edge2]
		graph = Graph(vertices, edges, True, Graph.ADJACENCY_MATRIX)
		graph.transpose()
		adjacencies = graph.adjacencies
		self.assertEqual(adjacencies, [[None, None, None], [self.vertex, None, None], [None, self.vertex2, None]])
Exemple #2
1
	def test_transpose(self):
		vertices = [self.vertex, self.vertex2, self.vertex3]
		edges = [self.edge, self.edge2]
		graph = Graph(vertices, edges, False)
		adjacencies = graph.adjacencies
		graph.transpose()
		adjacencies2 = graph.adjacencies
		self.assertEqual(adjacencies, adjacencies2)

		graph = Graph(vertices, edges)
		graph.transpose()
		adjacencies = graph.adjacencies
		self.assertEqual(adjacencies, [[], [self.vertex], [self.vertex2]])
Exemple #3
0
	def test_adjacency_of(self):
		vertices = [self.vertex, self.vertex2, self.vertex3]
		edges = [self.edge, self.edge2]
		graph = Graph(vertices, edges)
		adjacency = graph.adjacency_of(self.vertex)
		self.assertEqual(adjacency, [self.vertex2])
		adjacency = graph.adjacency_of(Vertex())
		self.assertEqual(adjacency, [])
Exemple #4
0
	def test_universal_sink(self):
		vertices = [self.vertex, self.vertex2, self.vertex3]
		edges = [self.edge, self.edge2]
		graph = Graph(vertices, edges, True)
		vertex = graph.find_universal_sink()
		self.assertIsNone(vertex)

		edges.append(Edge(self.vertex, self.vertex3))
		graph = Graph(vertices, edges, True)
		vertex = graph.find_universal_sink()
		self.assertEquals(vertex, self.vertex3)
Exemple #5
0
	def test_indegree_matrix(self):
		vertex4 = Vertex()
		edge3 = Edge(self.vertex, vertex4)
		vertices = [self.vertex, self.vertex2, self.vertex3, vertex4]
		edges = [self.edge, self.edge2, edge3]
		graph = Graph(vertices, edges, True, Graph.ADJACENCY_MATRIX)
		self.assertEqual(graph.indegree(self.vertex), 0)
		self.assertEqual(graph.indegree(self.vertex2), 1)
		self.assertEqual(graph.indegree(self.vertex3), 1)
		self.assertEqual(graph.indegree(vertex4), 1)
		self.assertEqual(graph.indegree(Vertex()), 0)
Exemple #6
0
	def test_indegree_list(self):
		vertex4 = Vertex()
		edge3 = Edge(self.vertex, vertex4)
		vertices = [self.vertex, self.vertex2, self.vertex3, vertex4]
		edges = [self.edge, self.edge2, edge3]
		graph = Graph(vertices, edges)
		self.assertEqual(graph.indegree(self.vertex), 0)
		self.assertEqual(graph.indegree(self.vertex2), 1)
		self.assertEqual(graph.indegree(self.vertex3), 1)
		self.assertEqual(graph.indegree(vertex4), 1)
		self.assertEqual(graph.indegree(Vertex()), 0)
Exemple #7
0
	def test_universal_sink_matrix(self):
		vertices = [self.vertex, self.vertex2, self.vertex3]
		edges = [self.edge, self.edge2]
		graph = Graph(vertices, edges, True, Graph.ADJACENCY_MATRIX)
		vertex = graph.find_universal_sink()
		self.assertIsNone(vertex)

		edges.append(Edge(self.vertex, self.vertex3))
		graph = Graph(vertices, edges, True, Graph.ADJACENCY_MATRIX)
		vertex = graph.find_universal_sink()
		self.assertEquals(vertex, self.vertex3)

		edges = [Edge(self.vertex2, self.vertex3)]
		graph = Graph(vertices, edges, True, Graph.ADJACENCY_MATRIX)
		vertex = graph.find_universal_sink()
		self.assertIsNone(vertex)