-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtitletest.py
More file actions
29 lines (23 loc) · 910 Bytes
/
titletest.py
File metadata and controls
29 lines (23 loc) · 910 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
""" Puts strings into title case """
import unittest
def title(s):
wordlist = s.split()
results = []
for w in wordlist:
results.append(w[0].upper()+w[1:])
return " ".join(results)
class TestTitle(unittest.TestCase):
def test_short_string(self):
base_str = "hi there"
teststr1 = title(base_str)
teststr2 = base_str.title()
self.assertEqual(teststr1, teststr2, \
"Results of two title-case functions do not match for string 'hi there'")
def test_longer_string(self):
base_str = "this is a slightly longer string for more testing"
teststr1 = title(base_str)
teststr2 = base_str.title()
self.assertEqual(teststr1, teststr2, \
"Results of two title-case functions do not match for string 'this is a slightly longer string for more testing'")
if __name__ == "__main__":
unittest.main()