Beispiel #1
0
def test_linked_list():
    w_object = model.W_PointersObject(space, None, 2)
    w_last = link(space.w_nil)
    w_lb1 = link(w_last)
    w_lb2 = link(w_lb1)
    w_lb3 = link(w_lb2)
    w_lb4 = link(w_lb3)
    w_first = link(w_lb4)
    linkedlist = wrapper.LinkedListWrapper(space, w_object)
    linkedlist.store_first_link(w_first)
    linkedlist.store_last_link(w_last)
    assert w_first is linkedlist.first_link()
    assert w_last is linkedlist.last_link()
    assert linkedlist.remove_first_link_of_list() is w_first
    assert linkedlist.remove_first_link_of_list() is w_lb4
    assert linkedlist.remove_first_link_of_list() is w_lb3
    assert not linkedlist.is_empty_list()
    assert linkedlist.remove_first_link_of_list() is w_lb2
    assert linkedlist.remove_first_link_of_list() is w_lb1
    assert linkedlist.remove_first_link_of_list() is w_last
    assert linkedlist.is_empty_list()
    linkedlist.add_last_link(w_first)
    assert linkedlist.first_link() is w_first
    assert linkedlist.last_link() is w_first
    linkedlist.add_last_link(w_last)
    assert linkedlist.first_link() is w_first
    assert linkedlist.last_link() is w_last
    py.test.raises(WrapperException, linkedlist.remove, space.w_nil)
    linkedlist.remove(w_first)
    assert linkedlist.first_link() is w_last
    linkedlist.store_first_link(w_first)
    wrapper.LinkWrapper(space, w_first).store_next_link(w_last)
    linkedlist.remove(w_last)
    assert linkedlist.last_link() is w_first
Beispiel #2
0
def test_accessor_generators():
    w_o = model.W_PointersObject(space, None, 1)
    w = wrapper.LinkWrapper(space, w_o)
    w_o._vars[0] = "hello"
    assert w.next_link() == "hello"
    w.store_next_link("boe")
    assert w.next_link() == "boe"
Beispiel #3
0
def link(w_next='foo'):
    w_object = model.W_PointersObject(space, None, 1)
    wrapper.LinkWrapper(space, w_object).store_next_link(w_next)
    return w_object