-
Notifications
You must be signed in to change notification settings - Fork 0
/
Repeating String.py
52 lines (31 loc) · 961 Bytes
/
Repeating String.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import unittest
def double_chr_1(str):
prep = []
output = ""
for chr in str:
prep.append(chr)
prep.append(chr)
for i in range(len(prep)):
output += prep[i]
return output
def double_chr_2(str):
result= ""
for chr in str:
result = result + chr + chr
return result
def double_chr_3(str):
for x in str:
yield x * 2
def double_chr_4(str):
return "".join([x + x for x in str])
class TestDoubleMethod(unittest.TestCase):
param_list = [("hello", "hheelllloo"), ("world", "wwoorrlldd")]
def test_doubel(self):
for p1, p2 in self.param_list:
with self.subTest():
self.assertEqual(double_chr_1(p1), p2)
self.assertEqual(double_chr_2(p1),p2)
self.assertEqual("".join(double_chr_3(p1)), p2)
self.assertEqual(double_chr_4(p1), p2)
if __name__ == "__main__":
unittest.main()