mirror of
https://github.com/donnemartin/interactive-coding-challenges.git
synced 2024-03-22 13:11:13 +08:00
46 lines
1.2 KiB
Python
46 lines
1.2 KiB
Python
from nose.tools import assert_equal
|
|
|
|
|
|
class TestPalindrome(object):
|
|
|
|
def test_palindrome(self):
|
|
print('Test: Empty list')
|
|
linked_list = MyLinkedList()
|
|
assert_equal(linked_list.is_palindrome(), False)
|
|
|
|
print('Test: Single element list')
|
|
head = Node(1)
|
|
linked_list = MyLinkedList(head)
|
|
assert_equal(linked_list.is_palindrome(), False)
|
|
|
|
print('Test: Two element list, not a palindrome')
|
|
linked_list.append(2)
|
|
assert_equal(linked_list.is_palindrome(), False)
|
|
|
|
print('Test: General case: Palindrome with even length')
|
|
head = Node('a')
|
|
linked_list = MyLinkedList(head)
|
|
linked_list.append('b')
|
|
linked_list.append('b')
|
|
linked_list.append('a')
|
|
assert_equal(linked_list.is_palindrome(), True)
|
|
|
|
print('Test: General case: Palindrome with odd length')
|
|
head = Node(1)
|
|
linked_list = MyLinkedList(head)
|
|
linked_list.append(2)
|
|
linked_list.append(3)
|
|
linked_list.append(2)
|
|
linked_list.append(1)
|
|
assert_equal(linked_list.is_palindrome(), True)
|
|
|
|
print('Success: test_palindrome')
|
|
|
|
|
|
def main():
|
|
test = TestPalindrome()
|
|
test.test_palindrome()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main() |