1import unittest
2
3from solution import *
4
5
6class TestWords(unittest.TestCase):
7 """Tests for functions that return parts of the words."""
8
9 def test_simple_beginning(self):
10 """Sanity test for getting the beginning of a word."""
11 self.assertEqual(beginning('лиофилизиран'), 'лиоф')
12
13 def test_simple_middle(self):
14 """Sanity test for getting the middle of a word."""
15 self.assertEqual(middle('лиофилизиран'), 'илиз')
16
17 def test_simple_end(self):
18 """Sanity test for getting the end of a word."""
19 self.assertEqual(end('лиофилизиран'), 'иран')
20
21
22class TestSentence(unittest.TestCase):
23 """Tests for split_sentence."""
24
25 def test_simple_sentence(self):
26 """Sanity test for splitting a sentence into a list of split words."""
27 self.assertEqual(split_sentence('Продаваме лиофилизиран ананас'),
28 [('Про', 'дав', 'аме'),
29 ('лиоф', 'илиз', 'иран'),
30 ('ан', 'ан', 'ас')
31 ])
32
33
34if __name__ == '__main__':
35 unittest.main()
1import unittest
2
3from solution import *
4
5
6class TestWords(unittest.TestCase):
7 """Tests for functions that return parts of the words."""
8
9 def test_simple_beginning(self):
10 """Simple test for getting the beginning of a word."""
11 self.assertEqual(beginning('abc'), 'a')
12
13 def test_simple_middle(self):
14 """Simple test for getting the middle of a word."""
15 self.assertEqual(middle('abc'), 'b')
16
17 def test_simple_end(self):
18 """Simple test for getting the end of a word."""
19 self.assertEqual(end('abc'), 'c')
20
21 def test_exact_split(self):
22 """Test splitting a word that is an exact multiple of 3."""
23 word = '111222333'
24 self.assertEqual(beginning(word), '111')
25 self.assertEqual(middle(word), '222')
26 self.assertEqual(end(word), '333')
27
28 def test_remainder_1(self):
29 """Test splitting a word that has a remainder of 1 when divided by 3."""
30 word = 'аааббббввв'
31 self.assertEqual(beginning(word), 'ааа')
32 self.assertEqual(middle(word), 'бббб')
33 self.assertEqual(end(word), 'ввв')
34
35 def test_remainder_2(self):
36 """Test splitting a word that has a remainder of 2 when divided by 3."""
37 word = '🐍🐍🐍🙏🙏✔✔✔'
38 self.assertEqual(beginning(word), '🐍🐍🐍')
39 self.assertEqual(middle(word), '🙏🙏')
40 self.assertEqual(end(word), '✔✔✔')
41
42 def test_one_letter(self):
43 """Test with single letter."""
44 self.assertEqual(beginning('#'), '')
45 self.assertEqual(middle('#'), '#')
46 self.assertEqual(end('#'), '')
47
48 def test_empty_input(self):
49 """Test with empty input."""
50 self.assertEqual(beginning(''), '')
51 self.assertEqual(middle(''), '')
52 self.assertEqual(end(''), '')
53
54 def test_huge_input(self):
55 """Test with huge input."""
56 word = ''.join(['🙈'] * 10 + ['🙉'] * 10 + ['🙊'] * 10)
57 self.assertEqual(beginning(word), ''.join(['🙈'] * 10))
58 self.assertEqual(middle(word), ''.join(['🙉'] * 10))
59 self.assertEqual(end(word), ''.join(['🙊'] * 10))
60
61
62class TestSentence(unittest.TestCase):
63 """Tests for split_sentence."""
64
65 def test_simple_sentence(self):
66 """Simple test for splitting a sentence into a list of split words."""
67 self.assertEqual(split_sentence('abc abc abc'), [('a', 'b', 'c')] * 3)
68
69 def test_empty_sentence(self):
70 """Test with empty input."""
71 self.assertTrue(split_sentence('') in ([], [('', '', '')]))
72
73 def test_mixed_sentence(self):
74 """Test with mixed remainder input."""
75 self.assertEqual(split_sentence('Здравейте момчета къде ми е отвертката'),
76 [('Здр', 'аве' ,'йте'),
77 ('мо', 'мче', 'та'),
78 ('к', 'ъд', 'е'),
79 ('м', '', 'и'),
80 ('', 'е', ''),
81 ('отв', 'ертк', 'ата')])
82
83
84if __name__ == '__main__':
85 unittest.main()
Георги Кунчев
17.10.2023 00:23Тестовете ни при качване проверяват дали имената на функциите съвпадат с дефиницията на домашното, както и (в повечето случаи, но не винаги) дали функциите връщат искания тип данни.
Ще ти помогна с коментар в самото решение.
|
Магдалена Иванова
16.10.2023 22:07Здравейте! Качих решение, но ми даде грешка, че не съм спазила сигнатурата. Може ли да разясните какво се има в предвид в случая?
|