def test_circular_linked_list_with_random_numbers(helper):
    # test add_end() and remove_end()
    lst = helper.get_list(length=100)
    cll = CircularLinkedList()
    for i in lst:
        cll.add_end(i)
    assert len(cll) == len(lst)
    assert cll._head.get_data() == lst[0]
    assert not cll.is_empty()
    for _ in range(len(lst)):
        assert cll[0] == lst[0]
        cll.remove_end()
        lst.pop()
    assert len(cll) == 0
    assert cll.is_empty()
    # test add_front() and remove_front()
    lst = helper.get_list(length=100)
    for i in lst:
        cll.add_front(i)
    assert len(cll) == len(lst)
    assert cll._head.get_data() == lst[-1]
    assert not cll.is_empty()
    for _ in range(len(lst)):
        assert cll[0] == lst[-1]
        cll.remove_front()
        lst.pop()
    assert len(cll) == 0
    assert cll.is_empty()
def test_list_with_same_value(helper):
    length = helper.get_pos_int()
    val = helper.get_value()
    cll = CircularLinkedList()
    # test add_end
    for _ in range(length):
        cll.add_end(val)
    # test add_front
    for _ in range(length):
        cll.add_front(val)
    # test __setitem__()
    cll[1] = val
    assert cll == cll.reverse()
    assert cll == cll.copy()
    assert not cll.is_empty()
    assert len(cll) == 2 * length
    assert cll.count(val) == 2 * length
    assert cll.to_list() == [val] * (2 * length)
    # test split
    left_list, right_list = cll.split(length)
    assert len(left_list) == len(right_list) == length
    # test clear
    left_list.clear()
    right_list.clear()
    assert len(left_list) == len(right_list) == 0
    # test remove
    for i in range(length):
        if i > length // 2:
            cll.remove_end()
        else:
            cll.remove_front()
    assert len(cll) == cll.count(val) == length
    cll.remove(val, all=True)
    assert cll.is_empty()
    assert len(cll) == 0
def test_circular_linked_list_with_one_element(helper):
    val = helper.get_value()
    cll = CircularLinkedList()
    cll.insert(0, val)
    assert isinstance(cll._head, Node)
    assert cll._head.get_data() == val
    assert cll._head.get_next() == cll._head
    assert len(cll) == 1
    assert not cll.is_empty()
    assert val in cll
    assert [item for item in cll] == [val]
    assert cll.to_list() == [val]
    assert cll == cll.copy()
    assert cll == cll.reverse()
    # ==================== test rotate ====================
    assert cll == cll.rotate_left(helper.get_pos_int(), inplace=False)
    assert cll == cll.rotate_right(helper.get_pos_int(), inplace=False)
    # ==================== test operators ====================
    assert cll != CircularLinkedList()
    assert cll > CircularLinkedList()
    assert cll >= CircularLinkedList()
    assert CircularLinkedList() < cll
    assert CircularLinkedList() <= cll
    # ==================== test add/remove ====================
    new_value = helper.get_value()
    cll.add_front(new_value)
    cll.remove_front()
    cll.add_end(new_value)
    cll.remove_end()
    assert cll == CircularLinkedList([val])
    # ==================== test insert/split ====================
    with pytest.raises(IndexError):
        cll.insert(-1, helper.get_value())
    cll.insert(2, helper.get_value())  # shouldn't raise anything
    cll.split(helper.get_pos_int())  # shouldn't raise anything
def test_split_method(helper):
    lst = helper.get_list(length=100)
    cll = CircularLinkedList(lst)
    for i in range(len(lst)):
        # test left list
        left_list, right_list = cll.split(i)
        assert isinstance(left_list, LinkedList)
        assert left_list.to_list() == lst[:i]
        assert left_list.copy().to_list() == lst[:i]
        assert left_list.reverse().to_list() == lst[:i][::-1]
        # test right list
        assert isinstance(right_list, CircularLinkedList)
        assert right_list.to_list() == lst[i:]
        assert right_list.copy().to_list() == lst[i:]
        assert right_list.reverse().to_list() == lst[i:][::-1]
    cll.add_front(0)
    cll.add_end("apple")
    assert cll._length == len(cll) == len(lst) + 2
    assert cll.to_list() == [0] + lst + ["apple"]
def test_creating_circular_linked_list_from_constructor(helper):
    # Using constructor
    val = helper.get_value()
    cll = CircularLinkedList()
    cll.add_front(val)
    assert isinstance(cll._head, Node)
    assert cll._head.get_data() == val
    assert cll._head.get_next() == cll._head._next == cll._head
    assert len(cll) == cll._length == 1
    assert cll.to_list() == [item for item in cll] == [val]
    # Using Node
    cll = CircularLinkedList()
    with pytest.raises(TypeError):
        cll.add_front(DoublyNode(helper.get_value()))
    val = helper.get_value()
    cll = CircularLinkedList()
    cll.add_end(val)
    assert isinstance(cll._head, Node)
    cll._head.get_data() == val
    cll._head.get_next() == cll._head._next == cll._head
    assert len(cll) == cll._length == 1
    assert cll.to_list() == [item for item in cll] == [val]
def test_circular_linked_list_with_known_values():
    cll = CircularLinkedList()
    cll.add_front(10)
    cll.add_front(5)
    assert cll.to_list() == [5, 10]
    cll.remove(20)
    cll.remove_front()
    assert cll == CircularLinkedList([10])
    cll.remove_end()
    assert cll == CircularLinkedList()
    cll.insert(0, 100)
    cll.insert(1, 200)
    cll.insert(1, 100)
    assert 100 in cll and 200 in cll
    assert cll == CircularLinkedList([100, 100, 200])
    assert cll.copy().to_list() == [100, 100, 200]
    assert cll.reverse() == CircularLinkedList([200, 100, 100])
    cll.remove(100)
    rev = cll.reverse()
    assert cll == rev == CircularLinkedList([200])
    cll.clear()
    assert not rev.is_empty()
    assert cll.is_empty()
    # ==================================================
    cll = LinkedList()
    cll.add_front(6)
    cll.add_end(20)
    cll.insert(1, 10)
    cll.insert(2, 77)
    cll.insert(4, 43)
    cll.insert(0, 2)
    assert 43 in cll
    assert cll[1:4].to_list() == [6, 10, 77]
    assert cll.copy().to_list() == [2, 6, 10, 77, 20, 43]
    del cll[len(cll) - 1]
    assert cll.reverse().to_list() == [20, 77, 10, 6, 2]
    assert cll._length == len(cll) == 5
    cll.clear()
    assert cll.is_empty()