コード例 #1
0
    def test_swap_places_with_same_parent(self):
        node = Node(32)
        left = Node(42, parent=node)
        right = Node(52, parent=node)

        node.left = left
        node.right = right
        left.swap_places(right)

        self.assertIs(right, node.left)
        self.assertIs(left, node.right)
コード例 #2
0
    def test_swap_children(self):
        node = Node(32)
        left = Node(12, parent=node)
        right = Node(42, parent=node)

        node.left = left
        node.right = right
        node.swap_children()

        self.assertIs(right, node.left)
        self.assertIs(left, node.right)
コード例 #3
0
    def test_replace_child(self):
        node = Node(32)
        left = Node(100, parent=node)
        other = Node(44)

        node.left = left
        node.replace_child(node.left, other)

        self.assertEquals(other, node.left)
        self.assertIs(node, left.parent)
        self.assertIsNone(other.parent)
コード例 #4
0
 def test_is_leaf_is_not_true_when_children_are_present(self):
     node = Node(32)
     node.left = Node(100, parent=node)
     self.assertFalse(node.is_leaf())
コード例 #5
0
 def test_is_full_is_not_true_when_less_than_two_children_are_present(self):
     node = Node(32)
     node.left = Node(100, parent=node)
     self.assertFalse(node.is_full())
コード例 #6
0
 def test_is_leaf(self):
     node = Node(32)
     self.assertTrue(node.is_leaf())
コード例 #7
0
 def test_is_full(self):
     node = Node(32)
     node.left = Node(100, parent=node)
     node.right = Node(300, parent=node)
     self.assertTrue(node.is_full())
コード例 #8
0
 def test_has_right_is_not_true_when_there_is_no_right_child(self):
     node = Node(32)
     self.assertFalse(node.has_right())
コード例 #9
0
 def test_has_right(self):
     node = Node(32)
     node.right = Node(100, parent=node)
     self.assertTrue(node.has_right())
コード例 #10
0
 def test_choose_child_returns_right_when_only_right_is_present(self):
     node = Node(32)
     node.right = Node(42, parent=node)
     self.assertIs(node.right, node.choose_child())
コード例 #11
0
 def test_choose_child_returns_none_when_no_children_are_present(self):
     node = Node(32)
     self.assertIs(None, node.choose_child())