-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreadReverse unit test.py
More file actions
29 lines (24 loc) · 880 Bytes
/
readReverse unit test.py
File metadata and controls
29 lines (24 loc) · 880 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
29
import unittest
def readReverse(n):
i = n.find(' ') #finds spaces in input
if i == -1: #checks if there are no spaces
return n[::-1] #reverses input
else:
return n[:i][::-1] + ' ' + readReverse(n[i+1:]) #splits first word and reverses then second etc.
class readReverseTests(unittest.TestCase):
def testOne(self):
s = (readReverse("computer"))
self.assertEqual(s, "retupmoc")
def testTwo(self):
s = (readReverse("computer science"))
self.assertEqual(s, "retupmoc ecneics")
def testThree(self):
s = (readReverse("computer"))
self.assertNotEqual(s, "computer")
def testFour(self):
s = (readReverse("computer science"))
self.assertNotEqual(s, "computer science")
def main():
unittest.main()
if __name__ == '__main__':
main()