-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d4f73c7
commit 42bdcef
Showing
13 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 2 additions & 0 deletions
2
...es/filter_and_sort_dictionaries/README.md → ..._and_sort_dictionaries_with_llm/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
5_tdd_with_llms/examples/repeat_character_from_et6_workshop/repeat_character.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
""" Repeat Character | ||
Write a function that takes in a string, a single character, and a number. | ||
The function returns a string with each occurrence of the character repeated n times. | ||
""" | ||
|
||
def repeat_character(text: str, char_to_repeat: str, repetitions: int) -> str: | ||
"""The function returns a string with each occurrence of the character repeated n times. | ||
Parameters: | ||
text (str): we will repeat the character in this string | ||
char_to_repeat (str): this is the character we want to repeat | ||
repetitions (int): how many times to repeat the character | ||
Returns: | ||
string: the string with a single character repeated | ||
Raises: | ||
AssertionError: if the first argument is not a string | ||
AssertionError: if the second argument is not a single character | ||
AssertionError: if the third argument is not an integer | ||
AssertionError: if the third argument is less than 0 | ||
>>> repeat_character('Omnia', 'm', 7) | ||
'Ommmmmmmnia' | ||
>>> repeat_character('Jola-Moses', 's', 2) | ||
'Jola-Mossess' | ||
>>> repeat_character('Hasan', 'e', 999999999999) | ||
'Hasan' | ||
>>> repeat_character('Rafaa', 'a', 3) | ||
'Raaafaaaaaa' | ||
""" | ||
|
||
assert isinstance(repetitions, int), 'third argument must be an integer' | ||
assert repetitions >= 0, 'third argument cannot be less than 0' | ||
|
||
repeated_text = '' | ||
|
||
for char in text: | ||
if char.lower() == char_to_repeat.lower(): | ||
# repeated_text += char_to_repeat * repetitions | ||
repeated_text += char * repetitions | ||
else: | ||
repeated_text += char | ||
|
||
return repeated_text |
57 changes: 57 additions & 0 deletions
57
5_tdd_with_llms/examples/repeat_character_from_et6_workshop/tests/test_repeat_character.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env python3 | ||
# -*- coding: utf-8 -*- | ||
""" | ||
""" | ||
|
||
import unittest | ||
from ..repeat_character import repeat_character | ||
|
||
class TestRepeatCharacter(unittest.TestCase): | ||
"""""" | ||
|
||
def test_empty_string(self): | ||
"""it should return an empty if you pass an empty string""" | ||
self.assertEqual(repeat_character('', '!', 100000000000), "") | ||
|
||
def test_zero_repetitions(self): | ||
"""it should return the same string without the repeated char""" | ||
self.assertEqual(repeat_character('agabani', 'a', 0), "gbni") | ||
|
||
def test_repeat_character_seven_times(self): | ||
"""It should repeat 'm' 7 times in Omnia""" | ||
self.assertEqual(repeat_character('Omnia', 'm', 7), "Ommmmmmmnia") | ||
|
||
def test_character_with_more_than_one(self): | ||
"""It should repeat 's' 2 times in Jola-Moses""" | ||
self.assertEqual(repeat_character('Jola-Moses', 's', 2), 'Jola-Mossess') | ||
|
||
def test_character_doesnt_exist(self): | ||
"""It should repeat nothing in Hasan because there is no 'e'""" | ||
self.assertEqual(repeat_character('Hasan', 'e', 999999999999), 'Hasan') | ||
|
||
def test_characters_that_are_next_to_each_other(self): | ||
"""It should repeat characters even if they're already repeated""" | ||
self.assertEqual(repeat_character('Rafaa', 'a', 3), 'Raaafaaaaaa') | ||
|
||
def test_case_insensitive_upper_text(self): | ||
"""it should be case insensitive when the text is upper and the char is lower""" | ||
self.assertEqual(repeat_character('Agabani', 'a', 0), "gbni") | ||
|
||
def test_case_insensitive_upper_char(self): | ||
"""it should be case insensitive when the text is lower and the char is upper""" | ||
self.assertEqual(repeat_character('Agabani', 'A', 0), "gbni") | ||
|
||
def test_case_insensitive_with_non_zero_repetition(self): | ||
"""it should be case insensitive and repeat characters""" | ||
self.assertEqual(repeat_character('Agabani', 'A', 2), "AAgaabaani") | ||
|
||
# test defensive assertions | ||
def test_defensive_check_repetitions_is_not_int(self): | ||
"""it should raise an error if the reptitions is not an integer""" | ||
with self.assertRaises(AssertionError): | ||
repeat_character('Agabani', 'A', '3' ) | ||
|
||
def test_defensive_check_for_negative_repetitions(self): | ||
"""it should raise an error if the reptitions is less than 0""" | ||
with self.assertRaises(AssertionError): | ||
repeat_character('Agabani', 'A', -2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +0,0 @@ | ||
|
||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters