comparison test/testgraph.py @ 337:b00219172a42

Added cool lm3s811 qemu project
author Windel Bouwman
date Thu, 20 Feb 2014 20:04:52 +0100
parents e9fe6988497c
children 86b02c98a717
comparison
equal deleted inserted replaced
336:d1ecc493384e 337:b00219172a42
11 11
12 class GraphTestCase(unittest.TestCase): 12 class GraphTestCase(unittest.TestCase):
13 def testEdge(self): 13 def testEdge(self):
14 g = Graph() 14 g = Graph()
15 n1 = Node(g) 15 n1 = Node(g)
16 g.addNode(n1) 16 g.add_node(n1)
17 n2 = Node(g) 17 n2 = Node(g)
18 g.addNode(n2) 18 g.add_node(n2)
19 g.addEdge(n1, n2) 19 g.addEdge(n1, n2)
20 self.assertTrue(g.hasEdge(n2, n1)) 20 self.assertTrue(g.hasEdge(n2, n1))
21 self.assertTrue(g.hasEdge(n1, n2)) 21 self.assertTrue(g.hasEdge(n1, n2))
22 g.delNode(n1) 22 g.delNode(n1)
23 g.delNode(n2) 23 g.delNode(n2)
24 24
25 def testDegree(self): 25 def testDegree(self):
26 g = Graph() 26 g = Graph()
27 n1 = Node(g) 27 n1 = Node(g)
28 g.addNode(n1) 28 g.add_node(n1)
29 n2 = Node(g) 29 n2 = Node(g)
30 g.addNode(n2) 30 g.add_node(n2)
31 n3 = Node(g) 31 n3 = Node(g)
32 g.addNode(n3) 32 g.add_node(n3)
33 g.addEdge(n1, n2) 33 g.addEdge(n1, n2)
34 g.addEdge(n1, n3) 34 g.addEdge(n1, n3)
35 self.assertEqual(2, n1.Degree) 35 self.assertEqual(2, n1.Degree)
36 self.assertEqual(1, n2.Degree) 36 self.assertEqual(1, n2.Degree)
37 g.delNode(n2) 37 g.delNode(n2)
42 def testSuccessor(self): 42 def testSuccessor(self):
43 g = DiGraph() 43 g = DiGraph()
44 a = DiNode(g) 44 a = DiNode(g)
45 b = DiNode(g) 45 b = DiNode(g)
46 c = DiNode(g) 46 c = DiNode(g)
47 g.addNode(a) 47 g.add_node(a)
48 g.addNode(b) 48 g.add_node(b)
49 g.addNode(c) 49 g.add_node(c)
50 g.addEdge(a, b) 50 g.addEdge(a, b)
51 g.addEdge(b, c) 51 g.addEdge(b, c)
52 self.assertEqual({b}, a.Succ) 52 self.assertEqual({b}, a.Succ)
53 self.assertEqual({b}, c.Pred) 53 self.assertEqual({b}, c.Pred)
54 g.delNode(c) 54 g.delNode(c)