-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_string_thing_unittest.py
31 lines (23 loc) · 1.05 KB
/
test_string_thing_unittest.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
import unittest
from string_thing import StringThing
class TestStringThing(unittest.TestCase):
def test_one(self):
value = "123456"
st = StringThing(value)
result = st.length()
self.assertEqual(result, 6, f"Length of {value} - actual result: {result}, expected result: 6")
def test_substring_count(self):
value = "abcaabbbcccc"
st = StringThing(value)
# Note could be argued that right result for "cc" should be 3 rather than 2
expecteds = {"a": 3, "b": 4, "c": 5, "d": 0, "ab": 2, "cc": 2}
for substr, expected in expecteds.items():
result = st.substring_count(substr)
self.assertEqual(result, expected, f"Count of {substr} in {value} found {result} but expected {expected}")
def test_find_first(self):
value = "axbxxcxxxd"
st = StringThing(value)
result = st.find_first("b")
self.assertEqual(result, 2, f"Find first b in {value} - actual result: {result}, expected result: 2")
if __name__ == '__main__':
unittest.main()