def test_remove_deque(self): test_deque = deque.Deque() test_deque.add_front("cat") test_deque.add_front("dog") test_deque.add_front(1) self.assertEqual(test_deque.remove_rear(), "cat") self.assertEqual(test_deque.remove_front(), 1)
def test_add_deque(self): test_deque = deque.Deque() test_deque.add_front("cat") self.assertEqual(test_deque.size(), 1) test_deque.add_front("dog") self.assertEqual(test_deque.size(), 2) test_deque.add_front(1) self.assertEqual(test_deque.size(), 3)
def isPalindrome(string): """check if the given string is a palindrome return: boolean """ d = deque.Deque() for char in string: d.addFront(char) times = d.size() // 2 for _ in range(times): if not d.removeFront() == d.removeRear(): return False return True
def palchecker(astring): char = deque.Deque() for ch in astring: char.addrear(ch) print(char.items) stillequal = True while char.size() > 1 and stillequal: first = char.removefront() print("first-->", first) last = char.removerear() print("last-->", last) if first != last: stillequal = False return stillequal
def __init__(self, capacity=10): self.lru_deque = deque.Deque() self.MAX_CAPACITY = capacity self.current_capacity = 0 self.node_map = {}
def my_deque(self): return deque.Deque(6)
def test_create_deque(self): test_deque = deque.Deque() self.assertEqual(test_deque.is_empty(), True) self.assertEqual(test_deque.size(), 0)