Skip to content

Instantly share code, notes, and snippets.

@stephen-bunn
Created May 6, 2019 20:00
Show Gist options
  • Save stephen-bunn/2fa007ce1aca3fc89b3d8cf8b2023269 to your computer and use it in GitHub Desktop.
Save stephen-bunn/2fa007ce1aca3fc89b3d8cf8b2023269 to your computer and use it in GitHub Desktop.
Medium - Basic unittest example for is_palindrome
"""Basic unittest for ``is_palindrome`` method."""
import unittest
def is_palindrome(string: str) -> bool:
"""Determine if a given string is a palindrome.
:param str string: The string to process
:return: True if given string is a palindrome, otherwise False
:rtype: bool
"""
return string == string[::-1]
class TestPalindrome(unittest.TestCase):
"""Tests the ``is_plaindrome`` method."""
def test_is_palindrome(self):
"""Test true cases for ``is_palindrome``."""
assert is_palindrome("")
assert is_palindrome("a")
assert is_palindrome("aba")
assert is_palindrome("ababa")
assert is_palindrome("racecar")
def test_not_is_palindrome(self):
"""Test false cases for ``is_palindrome``."""
assert not is_palindrome("ab")
assert not is_palindrome("abab")
assert not is_palindrome("abaa")
assert not is_palindrome("bbaa")
if __name__ in "__main__":
unittest.main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment