Python Forum
Homework Python unit test
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework Python unit test
#2
This is an error waiting to happen:
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__".
Reply


Messages In This Thread
Homework Python unit test - by Paragoon2 - Dec-10-2022, 07:46 PM
RE: Homework Python unit test - by deanhystad - Dec-11-2022, 12:23 AM
RE: Homework Python unit test - by Paragoon2 - Dec-11-2022, 11:37 AM
RE: Homework Python unit test - by deanhystad - Dec-12-2022, 04:56 AM
RE: Homework Python unit test - by Paragoon2 - Dec-12-2022, 12:45 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  HELP in python homework makashito 4 4,996 Oct-12-2021, 10:12 AM
Last Post: buran
  CyperSecurity Using Python HomeWork ward1995 1 2,601 Jul-08-2021, 03:55 PM
Last Post: buran
Exclamation urgent , Python homework alm 2 3,326 May-09-2021, 11:19 AM
Last Post: Yoriz
  Homework with python Johnsonmfw 1 2,309 Sep-20-2020, 04:03 AM
Last Post: ndc85430
  Unit Testing is not showing Test case result mbilalshafiq 2 2,576 Jul-01-2020, 08:50 PM
Last Post: mbilalshafiq
  Python Homework Help *Urgent GS31 2 3,389 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Help with Unit Tests pdub787 3 4,028 Nov-20-2019, 07:45 PM
Last Post: ndc85430
  Python Homework Question OrcDroid123 1 3,172 Sep-01-2019, 08:44 AM
Last Post: buran
  Python homework / functions sunhyunshine 1 3,092 May-11-2019, 05:37 PM
Last Post: MrTheOne
  python homework help ASAP gk34332 1 3,624 Mar-13-2019, 07:27 PM
Last Post: ichabod801

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020