コード例 #1
0
def test_get_middel_values():
    new_list = SinglyLinkedList()
    new_list.addAtHead(3)
    new_list.addAtHead(2)
    new_list.addAtTail(5)
    new_list.addAtTail(6)

    assert new_list.get(1) == 3
    assert new_list.get(2) == 5
コード例 #2
0
def test_custom_operations():
    new_list = SinglyLinkedList()
    new_list.addAtIndex(0, 10)
    new_list.addAtIndex(0, 20)
    new_list.addAtIndex(1, 30)

    assert new_list.head.val == 20
    assert new_list.tail.val == 10
    assert new_list.length == 3
    assert new_list.get(0) == 20
コード例 #3
0
def test_linked_list_delete_middle():
    new_list = SinglyLinkedList()
    new_list.addAtHead(7)
    new_list.addAtHead(2)
    new_list.addAtHead(1)
    new_list.addAtIndex(3, 0)
    new_list.deleteAtIndex(2)
    new_list.addAtHead(6)
    new_list.addAtTail(4)

    assert new_list.head.val == 6
    assert new_list.tail.val == 4
    assert new_list.length == 4
    assert new_list.get(4) == 4
コード例 #4
0
    print(
        'Queue implementation using collections.deque (TC append() - O(1), TC popleft() - O(1))'
    )
    test_queue = deque()
    print(test_queue)
    test_queue.append(1)
    test_queue.append(2)
    test_queue.append(3)
    print(test_queue)
    test_queue.popleft()
    print(test_queue)
    test_queue.popleft()
    test_queue.popleft()
    print(test_queue)

    print()
    print(
        'Queue implementation using queue.Queue (TC put() - O(1), TC get() - O(1))'
    )
    test_queue = Queue()
    print(test_queue.qsize())
    test_queue.put(1)
    test_queue.put(2)
    test_queue.put(3)
    print(test_queue.qsize())
    test_queue.get()
    print(test_queue.qsize())
    test_queue.get()
    test_queue.get()
    print(test_queue.qsize())
コード例 #5
0
    print(
        'Stack implementation using collections.deque (TC append() - O(1), TC pop() - O(1))'
    )
    test_stack = deque()
    print(test_stack)
    test_stack.append(1)
    test_stack.append(2)
    test_stack.append(3)
    print(test_stack)
    test_stack.pop()
    print(test_stack)
    test_stack.pop()
    test_stack.pop()
    print(test_stack)

    print()
    print(
        'Stack implementation using queue.LifoQueue (TC put() - O(1), TC get() - O(1))'
    )
    test_stack = LifoQueue()
    print(test_stack.qsize())
    test_stack.put(1)
    test_stack.put(2)
    test_stack.put(3)
    print(test_stack.qsize())
    test_stack.get()
    print(test_stack.qsize())
    test_stack.get()
    test_stack.get()
    print(test_stack.qsize())
コード例 #6
0
def test_get_head_tail_val():
    new_list = SinglyLinkedList()
    new_list.addAtHead(5)
    new_list.addAtTail(6)
    assert new_list.get(0) == 5
    assert new_list.get(1) == 6