Dec-11-2022, 12:23 AM
This is an error waiting to happen:
Your example is not written correctly for testing (or for being useful). coding() and decoding() should not print, they should return the translated string. Once modified, you test can call them with a string and compare the returned string against the expected result.
selection() will be difficult to test because it calls input(). You need to replace the existing function with one that returns strings provided by the test. I don't see this as being worth the effort.
You should modify the example.py module so it doesn't run any code when imported. Write a main() function, and only call this function if __name__ == "__main__".
Output:dictionary={'A':'.-', 'B':'-...',
'C':'-.-.', 'D':'-..', 'E':'.','F':'..-.', 'G':'--.', 'H':'....',
'I':'..', 'J':'.---', 'K':'-.-','L':'.-..', 'M':'--', 'N':'-.',
'O':'---', 'P':'.--.', 'Q':'--.-','R':'.-.', 'S':'...', 'T':'-',
'U':'..-', 'V':'...-', 'W':'.--','X':'-..-', 'Y':'-.--', 'Z':'--..',}
dictionary2={'.-':'A','-...':'B','-.-.':'C','-..':'D', '.':'E','..-.':'F','--.':'G','....':'H',
'..':'I','.---':'J', '-.-':'K','.-..':'L', '--':'M', '-.':'N',
'---':'O', '.--.':'P', '--.-':'Q','.-.':'R', '...':'S', '-':'T',
'..-':'U', '...-':'V', '.--':'W','-..-':'X', '-.--':'Y', '--..':'Z',}
Instead writing a bunch of code that I will probably get wrong (good reason to test), I would build dictionary2 (terrible name) from dictionary (equally terrible name). Can do it in 1 line of Python code.Your example is not written correctly for testing (or for being useful). coding() and decoding() should not print, they should return the translated string. Once modified, you test can call them with a string and compare the returned string against the expected result.
selection() will be difficult to test because it calls input(). You need to replace the existing function with one that returns strings provided by the test. I don't see this as being worth the effort.
You should modify the example.py module so it doesn't run any code when imported. Write a main() function, and only call this function if __name__ == "__main__".