-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_graph_node.py
More file actions
34 lines (22 loc) · 814 Bytes
/
test_graph_node.py
File metadata and controls
34 lines (22 loc) · 814 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import unittest
from structures.graph import GraphNode
class TestGraph(unittest.TestCase):
def test_graph_node(self):
self.assertEqual(4,GraphNode(4).val)
def test_insert(self):
node = GraphNode(1)
two = GraphNode(2)
three = GraphNode(3)
node.add_adjacent(two)
self.assertTrue(two in node.adjacent_list)
self.assertFalse(three in node.adjacent_list)
three.add_adjacent(three)
self.assertTrue(two in node.adjacent_list)
def test_delete(self):
node = GraphNode(1)
two = GraphNode(2)
node.add_adjacent(two)
node.remove_adjacent(two)
self.assertTrue(two not in node.adjacent_list)
with self.assertRaises(KeyError):
node.remove_adjacent(GraphNode(1))