Created
March 14, 2016 06:36
-
-
Save cnbeining/b81e4ca699028d590b37 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class TestBT(unittest.TestCase): | |
@timeout(4) | |
def setUp(self): | |
BTN = ex10.BTNode | |
self.node12 = BTN(12) | |
self.node11 = BTN(11, None, self.node12) | |
self.node10 = BTN(10, self.node11) | |
self.node9 = BTN(9) | |
self.node8 = BTN(8) | |
self.node7 = BTN(7) | |
self.node6 = BTN(6, self.node8) | |
self.node5 = BTN(5, self.node6, self.node7) | |
self.node4 = BTN(44) | |
self.node3 = BTN(3, self.node9, self.node10) | |
self.node2 = BTN(2, self.node4, self.node5) | |
self.node1 = BTN(1, self.node2, self.node3) | |
def tearDown(self): | |
pass | |
@timeout(4) | |
def test_set_depth_1(self): | |
self.node3.set_depth(0) | |
self.assertEqual(self.node1.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node2.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node3.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node4.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node5.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node6.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node7.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node8.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node9.depth, 1, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node10.depth, 1, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node11.depth, 2, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node12.depth, 3, "set_depth() does not correctly set the depth field.") | |
@timeout(4) | |
def test_set_depth_2(self): | |
self.node1.set_depth(0) | |
self.assertEqual(self.node1.depth, 0, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node2.depth, 1, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node3.depth, 1, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node4.depth, 2, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node5.depth, 2, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node6.depth, 3, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node7.depth, 3, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node8.depth, 4, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node9.depth, 2, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node10.depth, 2, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node11.depth, 3, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node12.depth, 4, "set_depth() does not correctly set the depth field.") | |
@timeout(4) | |
def test_set_depth_2(self): | |
self.node1.set_depth(3) | |
self.assertEqual(self.node1.depth, 3, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node2.depth, 4, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node3.depth, 4, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node4.depth, 5, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node5.depth, 5, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node6.depth, 6, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node7.depth, 6, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node8.depth, 7, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node9.depth, 5, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node10.depth, 5, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node11.depth, 6, "set_depth() does not correctly set the depth field.") | |
self.assertEqual(self.node12.depth, 7, "set_depth() does not correctly set the depth field.") | |
@timeout(4) | |
def test_leaves_and_internals_1(self): | |
returned = self.node12.leaves_and_internals() | |
self.assertTrue(isinstance(returned, tuple), "leaves_and_internals() does not return two sets.") | |
self.assertTrue(len(returned) == 2, "leaves_and_internals() does not return two sets.") | |
self.assertTrue(isinstance(returned[0], set), "leaves_and_internals() does not return two sets.") | |
self.assertTrue(isinstance(returned[1], set), "leaves_and_internals() does not return two sets.") | |
expected_leaves = {12} | |
expected_internals = set() | |
self.assertEqual(returned[0], expected_leaves, "The set of leaves returned is not correct") | |
self.assertEqual(returned[1], expected_internals, "The set of internals returned is not correct") | |
@timeout(4) | |
def test_leaves_and_internals_2(self): | |
returned = self.node10.leaves_and_internals() | |
self.assertTrue(isinstance(returned, tuple), "leaves_and_internals() does not return two sets.") | |
self.assertTrue(len(returned) == 2, "leaves_and_internals() does not return two sets.") | |
self.assertTrue(isinstance(returned[0], set), "leaves_and_internals() does not return two sets.") | |
self.assertTrue(isinstance(returned[1], set), "leaves_and_internals() does not return two sets.") | |
expected_leaves = {12} | |
expected_internals = {11} | |
self.assertEqual(returned[0], expected_leaves, "The set of leaves returned is not correct") | |
self.assertEqual(returned[1], expected_internals, "The set of internals returned is not correct") | |
@timeout(4) | |
def test_leaves_and_internals_3(self): | |
returned = self.node2.leaves_and_internals() | |
self.assertTrue(isinstance(returned, tuple), "leaves_and_internals() does not return two sets.") | |
self.assertTrue(len(returned) == 2, "leaves_and_internals() does not return two sets.") | |
self.assertTrue(isinstance(returned[0], set), "leaves_and_internals() does not return two sets.") | |
self.assertTrue(isinstance(returned[1], set), "leaves_and_internals() does not return two sets.") | |
expected_leaves = {44,7,8} | |
expected_internals = {5,6} | |
self.assertEqual(returned[0], expected_leaves, "The set of leaves returned is not correct") | |
self.assertEqual(returned[1], expected_internals, "The set of internals returned is not correct") | |
@timeout(4) | |
def test_leaves_and_internals_4(self): | |
returned = self.node1.leaves_and_internals() | |
self.assertTrue(isinstance(returned, tuple), "leaves_and_internals() does not return two sets.") | |
self.assertTrue(len(returned) == 2, "leaves_and_internals() does not return two sets.") | |
self.assertTrue(isinstance(returned[0], set), "leaves_and_internals() does not return two sets.") | |
self.assertTrue(isinstance(returned[1], set), "leaves_and_internals() does not return two sets.") | |
expected_leaves = {44,7,8,9,12} | |
expected_internals = {2,3,5,6,10,11} | |
self.assertEqual(returned[0], expected_leaves, "The set of leaves returned is not correct") | |
self.assertEqual(returned[1], expected_internals, "The set of internals returned is not correct") | |
@timeout(4) | |
def test_sum_to_deepest_1(self): | |
returned = self.node2.sum_to_deepest() | |
self.assertEqual(returned, 21) | |
@timeout(4) | |
def test_sum_to_deepest_2(self): | |
returned = self.node1.sum_to_deepest() | |
self.assertEqual(returned, 37) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment