-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweaveString unittest.py
More file actions
36 lines (31 loc) · 1.18 KB
/
weaveString unittest.py
File metadata and controls
36 lines (31 loc) · 1.18 KB
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
30
31
32
33
34
35
36
import unittest
def weaveString(n,r):
if not (n and r) : #checks if it doesnt exist
return n+r
return(n[0] + r[0] + weaveString(n[1:], r[1:])) #recursive function takes first element of string n and adds it to the first element of string r then the second and so forth
class weaveStringTests(unittest.TestCase):
def testOne(self):
s = (weaveString("computer","code"))
self.assertEqual(s, "ccoomdpeuter")
def testTwo(self):
s = (weaveString("computer", "computer"))
self.assertEqual(s, "ccoommppuutteerr")
def testThree(self):
s = (weaveString("",""))
self.assertEqual(s, "")
def testFour(self):
s = (weaveString("", "computer"))
self.assertEqual(s, "computer")
def testFive(self):
s = (weaveString("computer", ""))
self.assertEqual(s, "computer")
def testSix(self):
s = (weaveString("code","computer"))
self.assertEqual(s, "ccoodmeputer")
def testSeven(self):
s = (weaveString("code","computer"))
self.assertNotEqual(s, "sdfghhjkj")
def main():
unittest.main()
if __name__ == '__main__':
main()