Skip to main content
added proof code
Source Link
Roland Illig
  • 21.4k
  • 2
  • 34
  • 83

Your tests are already nice, but they don't cover everything.

A function that strips all non-letters, lowercases the resultlowercases the result and then only compares the initial with the final character would survive the tests, but shouldn't.

To prove the above, add the following code at the top of the test_palindromes.py file:

import re

def is_palindrome(word):
    tidied = re.sub('[^A-Za-z]', '', word)
    return tidied == '' or tidied[0] == tidied[-1]

Returning true if only any character matches instead of all is a common mistake, therefore the tests should prevent this mistake from being made.

Your tests are already nice, but they don't cover everything.

A function that strips all non-letters, lowercases the result and then only compares the initial with the final character would survive the tests, but shouldn't.

Your tests are already nice, but they don't cover everything.

A function that strips all non-letters, lowercases the result and then only compares the initial with the final character would survive the tests, but shouldn't.

To prove the above, add the following code at the top of the test_palindromes.py file:

import re

def is_palindrome(word):
    tidied = re.sub('[^A-Za-z]', '', word)
    return tidied == '' or tidied[0] == tidied[-1]

Returning true if only any character matches instead of all is a common mistake, therefore the tests should prevent this mistake from being made.

Source Link
Roland Illig
  • 21.4k
  • 2
  • 34
  • 83

Your tests are already nice, but they don't cover everything.

A function that strips all non-letters, lowercases the result and then only compares the initial with the final character would survive the tests, but shouldn't.