I have made a function that counts the number of vowels (and it works, according to the print).
I am a bit new to unit tests, and currently when I run the script, it is not saying 0 tests are ran.
What am I doing incorrect here?
import unittest
# data = raw_input("Please type a sentence: ")
def countVowels(string):
count = 0
for char in string:
if char in 'AEIOUaeiou':
count += 1
if count % 2 == 0:
return 'even'
else:
return 'odd'
class VowelTest(unittest.TestCase):
def even(self):
self.assertEqual(countVowels('Hello'), 'even')
def odd(self):
self.assertEqual(countVowels('Hi'), 'odd')
print countVowels("Hello")
print countVowels('hi')
if __name__ == '__main__':
unittest.main()
I think that the name of your tests, show begin with the word test
. For example:
def testAdding():
pass
def testSubtracting():
pass
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.