Esempio n. 1
0
 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)
Esempio n. 2
0
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)
Esempio n. 3
0
def test_verify_link_negative_right():
    left = Node("left")
    right = Node("right")
    left.right = right
    with pytest.raises(AssertionError):
        verify_link(left, right)
Esempio n. 4
0
def test_left_type_not_equal():
    node = Node()
    with pytest.raises(ValueError):
        badleft = "string"
        node.left = badleft
    assert(node.left is None)
Esempio n. 5
0
def test_node_left():
    node = Node("parent")
    left = Node("left")
    node.left = left
    assert(node.left is left)
Esempio n. 6
0
def test_right_type_not_equal():
    node = Node()
    with pytest.raises(ValueError):
        badright = "string"
        node.right = badright
    assert(node.right is None)
Esempio n. 7
0
def test_right_type_equal():
    node = Node("parent")
    right = Node("right")
    node.right = right
    assert(node.right is right)
Esempio n. 8
0
def test_node_create():
    node = Node("parent")
    assert(node != None)
Esempio n. 9
0
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)])