forked from gaborbencsik/zerda-exam-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy paththird.py
More file actions
35 lines (23 loc) · 991 Bytes
/
third.py
File metadata and controls
35 lines (23 loc) · 991 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
30
31
32
33
34
35
# Write unittests for this function:
import unittest
def count_letter_in_string(string, letter):
if type(string) != str:
return 0
count = 0
for current_letter in string:
if current_letter == letter:
count += 1
return count
class TestForExerciseThird(unittest.TestCase):
def test_CheckNormalWorking(self):
self.assertEqual(count_letter_in_string('almafa alatt alszik az alma', 'a'), 9)
def test_CheckFirstInputNotString(self):
self.assertEqual(count_letter_in_string(12345, 'a'), 0)
def test_CheckSecondInputNotString(self):
self.assertEqual(count_letter_in_string('almafa alatt alszik az alma', 5), 0)
def test_CheckGivenEmptyStringInput(self):
self.assertEqual(count_letter_in_string('', 'a'), 0)
def test_CheckGivenSecondInputAsList(self):
self.assertEqual(count_letter_in_string('almafa alatt alszik az alma', ['a', 'b']), 0)
if __name__ == '__main__':
unittest.main()