This Python program is an implementation to CS50’s Introduction to Programming with Python Week 5 - Testing my twttr Problem Set. The twttr.py
program is designed to remove all vowels (both uppercase and lowercase) from a given string. To ensure that the program functions correctly, a set of tests have been implemented in the test_twttr.py
file. These tests thoroughly test the shorten
function, checking its behavior against various inputs.
-
Open your terminal.
-
Navigate to the directory where you have saved both
twttr.py
andtest_twttr.py
.cd path/to/your/directory
-
Run the tests using the
pytest
command:pytest test_twttr.py
-
The tests will be executed, and the results will be displayed in the terminal.
def main():
text_to_shorten = input("Input: ")
print(f"Output: {shorten_text(text_to_shorten)}")
def shorten(word):
return "".join([ch for ch in word if ch.lower() not in "aeiou"])
if __name__ == "__main__":
main()
from twttr import shorten
def test_shorten():
assert shorten("cat") == "ct"
assert shorten("twitter") == "twttr"
assert shorten("APPLE") == "PPL"
assert shorten("Twitt3r") == "Twtt3r"
assert shorten("pr,@oud!") == "pr,@d!"
- Run the tests as mentioned in the "How to Run the Tests" section.
- The tests will be executed, and you will see the results in the terminal.
-
Shorten Word with Vowels:
- Input:
assert shorten("cat") == "ct"
- Input:
-
Shorten Word with Repeated Vowels:
- Input:
assert shorten("twitter") == "twttr"
- Input:
-
Shorten Uppercase Word:
- Input:
assert shorten("APPLE") == "PPL"
- Input:
-
Shorten Word with Numbers:
- Input:
assert shorten("Twitt3r") == "Twtt3r"
- Input:
-
Shorten Word with Special Characters:
- Input:
assert shorten("pr,@oud!") == "pr,@d!"
- Input:
- Ensure that the
twttr.py
andtest_twttr.py
files are saved in the same directory and have the correct names. - The
shorten_text
function is responsible for removing vowels from the given input string and returning the modified string. Thetest_shorten
function intest_twttr.py
tests theshorten
function using various inputs and expected outputs. - Running the tests using
pytest
will show whether your implementation of theshorten
function is working correctly. It's important to have both the correct and incorrect versions oftwttr.py
to validate your tests.