count_lowercase_vowels
def count_lowercase_vowels(s):
""" (str) -> int
Return the number of vowels (a, e, i, o, and u) in s.
>>> count_lowercase_vowels('Happy Anniversary!')
4
>>> count_lowercase_vowels('xyz')
0
"""
num_vowels = 0
for char in s:
if char in 'aeiou':
num_vowels = num_vowels + 1
return num_vowels
|
To test count_lowercase_vowels, we need to:
There are many possible for string lengths. For this example, we'll consider strings that have these lengths:
Which characters should we use? For this example, we'll choose
characters based on whether they are vowels or non-vowels. The actual
character doesn't matter.
If we want a non-vowel, we could use 'b', 'n', '?', or any other character that is not a vowel.
|
is_palindrome
def is_palindrome(s):
""" (str) -> bool
Return True if and only if s is a palindrome.
>>> is_palindrome('noon')
True
>>> is_palindrome('racecar')
True
>>> is_palindrome('dented')
False
"""
|
Because the function returns a Boolean value, we need at least 2 test cases: one that returns True and one that returns False. In this case, we actually need quite a few more than 2 test cases.
As for the previous example, we need to choose different values for the string argument that represent different categories of strings.
When we developed the code for is_palindrome(), we found
that whether a string was even or odd affected the code. Therefore, the
tests should consider strings that have even and odd lengths. For this
example, we'll consider strings that have these lengths:
The test cases are summarized in this table:
|
When choosing test cases, consider the following factors:
strings, lists, tuples, dictionaries) test with:
if statement checking when a value is 3; 3 is a threshold), test at the that threshold.
There is often overlap between the categories, so one test case may fall into more than 1 category.