class TestNodeMethods(unittest.TestCase): def setUp(self): # Tree from the task self.parent = Node(5) new_node1 = Node(3) new_node2 = Node(2) new_node3 = Node(5) new_node1.set_left_node(new_node2) new_node1.set_right_node(new_node3) self.parent.set_left_node(new_node1) new_node4 = Node(7) new_node4.set_left_node(Node(1)) new_node5 = Node(0) new_node5.set_left_node(Node(2)) new_node6 = Node(8) new_node6.set_right_node(Node(5)) new_node5.set_right_node(new_node6) new_node4.set_right_node(new_node5) self.parent.set_right_node(new_node4) def test_count(self): self.assertEqual(self.parent.get_count(), 10) def test_sum(self): self.assertEqual(self.parent.get_sum(), 38) def test_avg(self): self.assertEqual(self.parent.get_avg(), 3.8) def test_median(self): self.assertEqual(self.parent.get_median(), 4)
print('Empty node') print(node) print('Set value to 5') node.set_value(5) print(node) print('Create new node with value 3') node2 = Node(3) print(node2) print('Set node with value 3 as left node of the old one') node.set_left_node(node2) print(node) print('Parent node values') print('Sum: ', node.get_sum()) print('Avg: ', node.get_avg()) print('Count: ', node.get_count()) print('Median: ', node.get_median()) print() print('New node values') print('Sum: ', node2.get_sum()) print('Avg: ', node2.get_avg()) print('Count: ', node2.get_count()) print('Median: ', node2.get_median())