-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathtest_clone_graph.py
More file actions
31 lines (27 loc) · 1.11 KB
/
test_clone_graph.py
File metadata and controls
31 lines (27 loc) · 1.11 KB
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
from clone_graph import Node, clone_graph
import unittest
class TestCloneGraph(unittest.TestCase):
def test_returns_empty_node_if_no_neighbors(self):
"""Takes in a root node with no neighbors and returns an empty list"""
result = clone_graph(Node(1, []))
self.assertEqual(result.val, 1)
self.assertEqual(result.neighbors, [])
def test_returns_full_cloned_list(self):
"""Takes in graph and clones it"""
root = Node(1, [])
second = Node(2, [])
third = Node(3, [])
fourth = Node(4, [])
root.neighbors = [second, third]
second.neighbors = [third, fourth]
third.neighbors = [root, fourth]
fourth.neighbors = [second, root]
result = clone_graph(root)
self.assertEqual(result.val, 1)
self.assertEqual(len(result.neighbors), 2)
self.assertEqual(root.neighbors[0].val, 2)
self.assertEqual(len(root.neighbors[0].neighbors), 2)
self.assertEqual(root.neighbors[1].val, 3)
self.assertEqual(len(root.neighbors[1].neighbors), 2)
if __name__ == "__main__":
unittest.main()