Created
May 6, 2019 20:09
-
-
Save stephen-bunn/b33e00d06a6413213b3da9d83542a413 to your computer and use it in GitHub Desktop.
Medium - Pytest example tests for is_plaindrome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
"""Basic pytest for ``is_palindrome`` method.""" | |
from typing import List | |
import pytest | |
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] | |
@pytest.fixture | |
def palindromes() -> List[str]: | |
"""Pytest fixture which returns a list of palindromes. | |
:return: A list of palindrome strings. | |
:rtype: List[str] | |
""" | |
return ["", "a", "aba", "ababa", "racecar"] | |
@pytest.fixture | |
def not_palindromes() -> List[str]: | |
"""Pytest fixture which returns a list of non-palindromes. | |
:return: A list of non-palindrome strings. | |
:rtype: List[str] | |
""" | |
return ["ab", "abab", "abaa", "bbaa"] | |
def test_is_plaindrome(palindromes: List[str]): | |
"""Test true cases for ``is_palindrome``. | |
:param List[str] palindromes: A list of palindrome strings | |
""" | |
for value in palindromes: | |
assert is_palindrome(value) | |
def test_not_is_palindrome(not_palindromes: List[str]): | |
"""Test false cases for ``is_plaindrome``. | |
:param List[str] not_palindromes: A list of non-palindrome strings | |
""" | |
for value in not_palindromes: | |
assert not is_palindrome(value) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment