def test_appendleft(): Q = Deque(3) Q.append(2) Q.append(4) Q.append(6) Q.appendleft(0) assert Q.peek() == 0, "expected value of 0"
def test_popleft(): Q = Deque(3) Q.append(2) Q.append(4) Q.append(6) assert Q.popleft() == 2, \ "expected value of 2"
def base_data(): Q = Deque(5) Q.append(5) Q.append(10) Q.append(15) Q.append(20) Q.append(25) Q.popleft() Q.popleft() Q.append(35) Q.append(40) T = Deque(4) T.append("n") T.append("n+1") T.appendleft("n+2") T.appendleft("n+3") T.pop() T.append("n+4") return Q, T
def base_data(): Q = Deque(5) Q.append(5) Q.append(10) Q.append(15) Q.append(20) Q.append(25) Q.popleft() Q.popleft() Q.append(35) Q.append(40) T = Deque(4) T.append('n') T.append('n+1') T.appendleft('n+2') T.appendleft('n+3') T.pop() T.append('n+4') return Q, T
def test_mem_leakage(): Q = Deque(2) Q.append(1) A = object() ref = [] ref.append(sys.getrefcount(A)) Q.append(A) ref.append(sys.getrefcount(A)) Q.pop() ref.append(sys.getrefcount(A)) assert np.array_equal( ref, [2, 3, 2]), "expected pop to overwrite place in memory"
def test_len_empty(): Q = Deque(5) assert not Q
def test_len(items, length): Q = Deque(10) for item in items: Q.append(item) assert len(Q) == length, f"expected a length of {length}"
def test_peekleft(): Q = Deque(2) Q.append(1) Q.append(2) assert Q.peekleft() == 1, "expected value of 1"
def test_peek(): Q = Deque(2) Q.append(1) Q.append(2) assert Q.peek() == 2, "expected value of 2"
def test_append_and_pop(): Q = Deque(1) Q.append(1) assert Q.pop() == 1, "popped element in deque"
def test_push_pop_available(method): assert hasattr(Deque(5), method), f"Deque has no {method} method"