def test_op_prod_example_trees(self): def prod(a, b): """ Example operator function. Takes in two integers, returns their product. """ return a * b expected_1 = 27 expected_2 = 22680 expected_3 = -864 actual_1 = student.op_tree([[1, 9], 3], prod, 1) actual_2 = student.op_tree([[20, 9], [[9, 7], 2]], prod, 1) actual_3 = student.op_tree([[12], [3, 4, -2], [3]], prod, 1) self.assertEqual( actual_1, expected_1, "Expected op_tree(tree1, prod, 1) to be 27, but got %s" % actual_1) self.assertEqual( actual_2, expected_2, "Expected op_tree(tree2, prod, 1) to be 22680, but got %s" % actual_2) self.assertEqual( actual_3, expected_3, "Expected op_tree(tree3, prod, 1) to be -864, but got %s" % actual_3)
def test_op_sum_example_trees(self): def sumem(a, b): """ Example operator function. Takes in two integers, returns their sum. """ return a + b expected_1 = 13 expected_2 = 47 expected_3 = 20 actual_1 = student.op_tree([[1, 9], 3], sumem, 0) actual_2 = student.op_tree([[20, 9], [[9, 7], 2]], sumem, 0) actual_3 = student.op_tree([[12], [3, 4, -2], [3]], sumem, 0) self.assertEqual( actual_1, expected_1, "Expected op_tree(tree1, sumem, 0) to be 13, but got %s" % actual_1) self.assertEqual( actual_2, expected_2, "Expected op_tree(tree2, sumem, 0) to be 47, but got %s" % actual_2) self.assertEqual( actual_3, expected_3, "Expected op_tree(tree3, sumem, 0) to be 20, but got %s" % actual_3)
def test_op_search_greater_ten_example_trees(self): expected_1 = True expected_2 = False expected_3 = True actual_1 = student.op_tree(student.treeA, student.search_greater_ten, False) actual_2 = student.op_tree(student.treeB, student.search_greater_ten, False) actual_3 = student.op_tree(student.treeC, student.search_greater_ten, False) self.assertEqual(actual_1, expected_1, "Expected op_tree(treeA, search_greater_ten, False) to be True, but got %s" % actual_1) self.assertEqual(actual_2, expected_2, "Expected op_tree(treeB, search_greater_ten, False) to be False, but got %s" % actual_2) self.assertEqual(actual_3, expected_3, "Expected op_tree(treeC, search_greater_ten, False) to be True, but got %s" % actual_3)
def test_op_prod_example_trees(self): def prod(a,b): """ Example operator function. Takes in two integers, returns their product. """ return a * b expected_1 = 0 expected_2 = 162 expected_3 = 7168 actual_1 = student.op_tree(student.treeA, prod, 1) actual_2 = student.op_tree(student.treeB, prod, 1) actual_3 = student.op_tree(student.treeC, prod, 1) self.assertEqual(actual_1, expected_1, "Expected op_tree(treeA, prod, 1) to be 0, but got %s" % actual_1) self.assertEqual(actual_2, expected_2, "Expected op_tree(treeB, prod, 1) to be 162, but got %s" % actual_2) self.assertEqual(actual_3, expected_3, "Expected op_tree(treeC, prod, 1) to be 7168, but got %s" % actual_3)
def test_op_sum_example_trees(self): def sumem(a,b): """ Example operator function. Takes in two integers, returns their sum. """ return a + b expected_1 = 41 expected_2 = 18 expected_3 = 37 actual_1 = student.op_tree(student.treeA, sumem, 0) actual_2 = student.op_tree(student.treeB, sumem, 0) actual_3 = student.op_tree(student.treeC, sumem, 0) self.assertEqual(actual_1, expected_1, "Expected op_tree(treeA, sumem, 0) to be 41, but got %s" % actual_1) self.assertEqual(actual_2, expected_2, "Expected op_tree(treeB, sumem, 0) to be 21, but got %s" % actual_2) self.assertEqual(actual_3, expected_3, "Expected op_tree(treeC, sumem, 0) to be 37, but got %s" % actual_3)
def test_op_search_even_example_trees(self): expected_1 = False expected_2 = True expected_3 = True actual_1 = student.op_tree([[3, 13], 9], student.search_even, False) actual_2 = student.op_tree([[2, 3], [[7, 7], 9]], student.search_even, False) actual_3 = student.op_tree([[12], [2, 4, 2], [6]], student.search_even, False) self.assertEqual( actual_1, expected_1, "Expected op_tree(tree1, search_even, False) to be False, but got %s" % actual_1) self.assertEqual( actual_2, expected_2, "Expected op_tree(tree2, search_even, False) to be True, but got %s" % actual_2) self.assertEqual( actual_3, expected_3, "Expected op_tree(tree3, search_even, False) to be True, but got %s" % actual_3)