Skip to content

This program will implement commands and handler functions to encode and decode Morse code sequences.

Notifications You must be signed in to change notification settings

CRIS-CS-Python/morse-encoder-decoder

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

Morse Encoder Decoder

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

" 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. "

Unit Tests

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.

Unit Tests for morse.py

  • 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.

Encode Algorithm

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.

Decode Algorithm

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.

"Dunder main" containing commands and handlers

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)].

Usage

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

About

This program will implement commands and handler functions to encode and decode Morse code sequences.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages