This program will implement commands and handler functions to encode and decode Morse code sequences. See the Morse code translator program we have been using in class as an example of correct values.
But before we implement the command or algorithms in the functions, we will build the unit tests first.
" Test-Driven Development (TDD) is a technique for building software that guides software development by writing tests... In essence we follow three simple steps repeatedly:
- Write a test for the next bit of functionality you want to add.
- Write the functional code until the test passes.
- Refactor both new and old code to make it well structured. "
Refer back to the Unit Tests Tutorial assignment we completed previously. The test_calc.py
file from that tutorial should serve as a good example for how to create
unit tests.
- Create a file called
test_morse.py
- Create a header docstring comment with
- Your name, grade and course
- Title
- Program Description
- Create a class
TestMorse
containing two test methods:test_encode()
will provide correct values for the English text argument and Morse return value.test_decode()
will provide correct values for the Morse code argument and English text return value.
The encode(msg)
and decode(msg)
functions defined in morse.py
initially return the value 'TODO'
, so the tests will fail - that's okay for now.
Implement the algorithm in the encode(msg)
function of morse.py
so that it
passes the test in test_encode()
by returning the correct return value.
raise
a MorseValueError
exception for invalid input.
Implement the algorithm in the decode(msg)
function of morse.py
so that it
passes the test in test_decode()
by returning the correct return value.
raise
a MorseValueError
exception for invalid input.
Create a "dunder main" conditional statement that gets commands and messages
from the command line and calls the correponding handler function [encode(msg)
or decode(msg)
].
The program will be used from the command line like this:
py morse.py <encode|decode> "<message>"
examples:
py morse.py encode "Hello World"
.... . .-.. .-.. --- / .-- --- .-. .-.. -..
py morse.py decode ".... . .-.. .-.. --- / .-- --- .-. .-.. -.."
HELLO WORLD