def test_add_rear(self):
        """Test add rear method."""
        d = Dequeue()
        self.assertTrue(d._items == [])

        d.add_rear(1)
        d.add_rear(2)
        self.assertEqual(d._items, [1, 2])
    def test_size(self):
        """Test size method."""
        d = Dequeue()
        self.assertEqual(d.size(), 0)

        n = 10
        for number in range(1, n):
            d.add_rear(1)
            self.assertEqual(d.size(), number)
Exemplo n.º 3
0
def PalindromeDetector(string):
    dq = Dequeue()
    for letter in string:
        dq.add_rear(letter)

    while dq.size() > 1:
        if dq.remove_front() != dq.remove_rear():
            return False

    return True
Exemplo n.º 4
0
def palindrome_checker(word):
    """Return True if word reads the same forward and backward."""
    d = Dequeue()
    for character in word:
        d.add_rear(character)
    backwards = "".join([d.remove_rear() for character in word])

    if word == backwards:
        return True
    return False
    def test_remove_front(self):
        """Test remove front method."""
        d = Dequeue()
        d.add_rear(1)
        d.add_rear(2)
        d.add_rear(3)
        self.assertEqual(d._items, [1, 2, 3])

        front = d.remove_front()

        self.assertEqual(front, 1)
        self.assertEqual(d._items, [2, 3])
    def test_remove_rear(self):
        """Test remove rear method."""
        d = Dequeue()
        d.add_rear(1)
        d.add_rear(2)
        d.add_rear(3)
        self.assertEqual(d._items, [1, 2, 3])

        rear = d.remove_rear()

        self.assertEqual(rear, 3)
        self.assertEqual(d._items, [1, 2])
Exemplo n.º 7
0
def pal_checker(word):
    chardequeue = Dequeue()

    for char in word:
        chardequeue.add_rear(char)

    still_equal = True

    while chardequeue.size() > 1 and still_equal:
        first = chardequeue.remove_front()
        last = chardequeue.remove_rear()
        if first != last:
            still_equal = False

    return still_equal
Exemplo n.º 8
0
 def test_add_rear(self):
     d = Dequeue()
     self.assertEqual(d.items, [])
     d.add_rear("apple")
     d.add_rear("banana")
     self.assertEqual(d.items, ["apple", "banana"])