Assessment --- Writing Tests

Oct 2, 2014 • Ashwin Srinath
  1. Consider the following code:
    `
    def is_palindrome(n):</p>

    # checks if a given integer is a palindrome.
    # Returns True if it is, and False if it is not.
    # e.g., 121 is a palindrome, but 122 is not

    return str(n) == str(n)[::-1]
` Python functions will try to work with what you give them. Although the documentation for ` is_palindrome ` clearly says that it checks if an * integer * is palindromic, there's nothing to stop you from doing the following: `
>>> is_palindrome(3.3)
True
` What do you think `is_palindrome` should do when you pass it a `float` instead of an `int`? (a) Raise an error and stop the program (b) Print a warning message, but continue anyway (c) Nothing --- extra functionality is a good thing (d) Return ` None ` (e) Something else 2. Here are a couple of tests for this code: `
assert(is_palindrome(121) == True)
assert(is_palindrome(122) == False)
` What are some other tests you can think of for `is_palindrome`? Can you think of tests that it will fail? If so, what changes would you make to `is_palindrome` so that it can pass those tests?