コード例 #1
0
	def test_predecessors(self):
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set(["a"]),
			"e": set([])
		})
		with self.assertRaises(NotDigraphError):
			graph.predecessors("a")
コード例 #2
0
ファイル: test_digraph.py プロジェクト: paladini/UFSC-graphs
	def test_predecessors(self):
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set([]),
			"e": set([])
		}, digraph=True)
		self.assertTrue(graph.predecessors("a") == set(["b"]))
		self.assertEqual(len(graph.predecessors("a")), 1)
コード例 #3
0
ファイル: test_digraph.py プロジェクト: paladini/UFSC-graphs
	def test_disconnect_without_vertices(self):
		graph = Graph(digraph=True)
		self.assertFalse(graph.sucessors("a") == set(["c"]))
		self.assertFalse(graph.predecessors("a") == set(["c"]))
		self.assertEqual(graph.in_degree("a"), 0)
		self.assertEqual(graph.out_degree("a"), 0)
		graph.disconnect("a", "c")
		self.assertFalse(graph.sucessors("a") == set(["c"]))
		self.assertFalse(graph.predecessors("a") == set(["c"]))
		self.assertEqual(graph.in_degree("a"), 0)
		self.assertEqual(graph.out_degree("a"), 0)
コード例 #4
0
ファイル: test_digraph.py プロジェクト: paladini/UFSC-graphs
	def test_disconnect_with_inexistent_vertex(self):
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set([]),
			"e": set([])
		}, digraph=True)
		graph.disconnect("a", "z")
		graph.disconnect("a", "y")
		graph.disconnect("a", "h")
		self.assertFalse(graph.sucessors("a") == set([]))
		self.assertFalse(graph.predecessors("a") == set([]))
		self.assertNotEqual(graph.in_degree("a"), 0)
		self.assertNotEqual(graph.out_degree("a"), 0)
		self.assertTrue(graph.sucessors("a") == set(["b", "d"]))
		self.assertTrue(graph.predecessors("a") == set(["b"]))
		self.assertEqual(graph.in_degree("a"), 1)
		self.assertEqual(graph.out_degree("a"), 2)
コード例 #5
0
ファイル: test_digraph.py プロジェクト: paladini/UFSC-graphs
	def test_connect(self): 
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set([]),
			"e": set([])
		}, digraph=True)
		graph.connect("a", "c")
		self.assertTrue(graph.predecessors("a") == set(["b"]))
		self.assertTrue(graph.sucessors("a") == set(["b", "d", "c"]))
		self.assertEqual(graph.in_degree("a"), 1)
		self.assertEqual(graph.out_degree("a"), 3)