def insert(self, left, right, value): self.sanity() if (self.head is None): self.head = Node(value) self.head.right = self.head self.head.left = self.head self.tail = self.head return self.head return insert_data(left, right, value)
def setup_nodes(): left = Node("left") right = Node("right") left.left = right left.right = right right.left = left right.right = left midleft = insert_data(left, right, "midleft") midright = insert_data(midleft, right, "midright") verify_links([(right, left), (left, midleft), (midleft, midright), (midright, right)]) return (left, midleft, midright, right)
def test_verify_link_negative_right(): left = Node("left") right = Node("right") left.right = right with pytest.raises(AssertionError): verify_link(left, right)
def test_left_type_not_equal(): node = Node() with pytest.raises(ValueError): badleft = "string" node.left = badleft assert(node.left is None)
def test_node_left(): node = Node("parent") left = Node("left") node.left = left assert(node.left is left)
def test_right_type_not_equal(): node = Node() with pytest.raises(ValueError): badright = "string" node.right = badright assert(node.right is None)
def test_right_type_equal(): node = Node("parent") right = Node("right") node.right = right assert(node.right is right)
def test_node_create(): node = Node("parent") assert(node != None)
def test_insert_node_midright_right(): (left, midleft, midright, right) = setup_nodes() new = Node("new") insert_node(midright, right, new) verify_links([(left, midleft), (midleft, midright), (midright, new), (new, right), (right, left)])