-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathtest_string_utils.py
More file actions
63 lines (53 loc) · 1.97 KB
/
test_string_utils.py
File metadata and controls
63 lines (53 loc) · 1.97 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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import unittest
import string_utils
class TestStringUtils(unittest.TestCase):
def test_str_len(self):
test_cases = [
(7, "roberto"),
(4, "yoda")
]
for expected, word in test_cases:
with self.subTest(f"{word} -> {expected}"):
self.assertEqual(expected, string_utils.str_len(word))
def test_first_char(self):
test_cases = [
("r", "roberto"),
("y", "yoda")
]
for expected, word in test_cases:
with self.subTest(f"{word} -> {expected}"):
self.assertEqual(expected, string_utils.first_char(word))
def test_last_char(self):
test_cases = [
("o", "roberto"),
("a", "yoda")
]
for expected, word in test_cases:
with self.subTest(f"{expected} -> {word}"):
self.assertEqual(expected, string_utils.last_char(word))
def test_input_has_substring(self):
test_cases = [
("Roberto", "Rob", True),
("Yoda", "Dark", False)
]
for word, substring, expected in test_cases:
with self.subTest(f"{word}, {substring} -> {expected}"):
self.assertEquals(expected, string_utils.input_has_substring(word, substring))
def test_substring(self):
test_cases = [
("roberto", 0, 3, "rob"),
("yoda", 2, 4, "da")
]
for str_in, start, stop, expected in test_cases:
with self.subTest(f"{str_in}, {start}, {stop} -> {expected}"):
self.assertEqual(expected, string_utils.substring(str_in, start, stop))
def test_opposite_case(self):
test_cases = [
("Rob", "rOB"),
("yoda", "YODA")
]
for str_in, str_out in test_cases:
with self.subTest(f"{str_in} -> {str_out}"):
self.assertEqual(str_out, string_utils.opposite_case(str_in))
if __name__ == '__main__':
unittest.main()