Ejemplo n.º 1
0
 def test_remove_front(self):
     d = Dequeue()
     d.add_front("apple")
     d.add_front("banana")
     d.add_front("cherry")
     self.assertEqual(d.remove_front(), "cherry")
     self.assertEqual(d.items, ["banana", "apple"])
Ejemplo n.º 2
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
Ejemplo n.º 3
0
def check_palindrome(string_to_check):
    dq = Dequeue()
    dq.set_items(string_to_check)

    is_palindrome = True

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

    return is_palindrome
    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])
Ejemplo n.º 5
0
def check_palindrome(string_to_check):
    sanitised_string = re.sub("[^a-zA-Z]","", string_to_check).lower()
    
    dq = Dequeue()
    dq.set_items(sanitised_string)

    is_palindrome = True

    while dq.size() > 1:
        if dq.remove_front() != dq.remove_rear():
            is_palindrome = False
    
    return is_palindrome
Ejemplo n.º 6
0
class PalindromeChecker:
    def __init__(self):
        self.dq = Dequeue()

    def check_if_palindrome(self, word):
        self.dq.items = list(word)
        is_palindrome = True
        while self.dq.size() > 1:
            first_letter = self.dq.remove_front()
            last_letter = self.dq.remove_rear()
            if first_letter != last_letter:
                is_palindrome = False

        return is_palindrome
Ejemplo 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
Ejemplo n.º 8
0
 def test_remove_empty(self):
     d = Dequeue()
     self.assertEqual(d.items, [])
     self.assertEqual(d.remove_front(), None)
     self.assertEqual(d.remove_rear(), None)