Пример #1
0
	def test_disconnect_without_vertices(self):
		graph = Graph()
		self.assertFalse(graph.adjacents_to("a") == set(["c"]))
		self.assertEqual(graph.degree("a"), 0)
		graph.disconnect("a", "c")
		self.assertFalse(graph.adjacents_to("a") == set(["c"]))
		self.assertEqual(graph.degree("a"), 0)
Пример #2
0
	def test_disconnect_with_inexistent_vertex(self):
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set(["a"]),
			"e": set([])
		})
		graph.disconnect("a", "z")
		graph.disconnect("a", "y")
		graph.disconnect("a", "h")
		self.assertFalse(graph.adjacents_to("a") == set([]))
		self.assertNotEqual(graph.degree("a"), 0)
		self.assertTrue(graph.adjacents_to("a") == set(["b", "d"]))
		self.assertEqual(graph.degree("a"), 2)
Пример #3
0
	def test_degree(self):
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set(["a"]),
			"e": set([])
		})
		self.assertEqual(len(graph.adjacents_to("a")), graph.degree("a"))
		self.assertEqual(len(graph.adjacents_to("a")), 2)
Пример #4
0
	def test_adjacents_to(self):
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set(["a"]),
			"e": set([])
		})
		adjancetsA = graph.adjacents_to("a")
		self.assertEqual(len(adjancetsA), 2)
		self.assertTrue(adjancetsA == set(["b", "d"]))
Пример #5
0
	def test_disconnect(self):
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set(["a"]),
			"e": set([])
		})
		graph.disconnect("a", "b")
		self.assertTrue(graph.adjacents_to("a") == set(["d"]))
		self.assertEqual(graph.degree("a"), 1)
Пример #6
0
	def test_adjacents_to(self):
		graph = Graph({
			"a": set(["b", "d"]), 
			"b": set(["a"]),
			"c": set([]),
			"d": set(["a"]),
			"e": set([])
		}, digraph=True)
		with self.assertRaises(DigraphError):
			adjancetsA = graph.adjacents_to("a")
			self.assertEqual(len(adjancetsA), 2)
			self.assertTrue(adjancetsA == set(["b", "d"]))
			raise Exception("Something went wrong in adjacents_to.")