1def beginning(word):
2 if len(word) % 3 != 2:
3 return word[:len(word) // 3]
4 return word[:len(word) // 3 + 1]
5
6
7def end(word):
8 if len(word) % 3 != 2:
9 return word[-(len(word) // 3):]
10 return word[-(len(word) // 3 + 1):]
11
12
13def middle(word):
14 if len(word) % 3 != 2:
15 return word[len(word) // 3: -(len(word) // 3)]
16 return word[len(word) // 3 + 1: -(len(word) // 3 + 1)]
17
18
19def split_sentence(sentence):
20 words = sentence.split()
21 return [(beginning(wordSplit), middle(wordSplit), end(wordSplit)) for wordSplit in words]
.F....F.....
======================================================================
FAIL: test_mixed_sentence (test.TestSentence)
Test with mixed remainder input.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 75, in test_mixed_sentence
self.assertEqual(split_sentence('Здравейте момчета къде ми е отвертката'),
AssertionError: Lists differ: [('Зд[49 chars]', 'е'), ('м', '', 'и'), ('', '', 'е'), ('отв', 'ертк', 'ата')] != [('Зд[49 chars]', 'е'), ('м', '', 'и'), ('', 'е', ''), ('отв', 'ертк', 'ата')]
First differing element 4:
('', '', 'е')
('', 'е', '')
[('Здр', 'аве', 'йте'),
('мо', 'мче', 'та'),
('к', 'ъд', 'е'),
('м', '', 'и'),
- ('', '', 'е'),
+ ('', 'е', ''),
('отв', 'ертк', 'ата')]
======================================================================
FAIL: test_one_letter (test.TestWords)
Test with single letter.
----------------------------------------------------------------------
Traceback (most recent call last):
File "/tmp/test.py", line 45, in test_one_letter
self.assertEqual(middle('#'), '#')
AssertionError: '' != '#'
+ #
----------------------------------------------------------------------
Ran 12 tests in 0.001s
FAILED (failures=2)
Георги Кунчев
17.10.2023 18:15Махаме една точка, заради неспазения `snake_case`.
|
15.10.2023 10:50