Dec-10-2022, 07:46 PM
Hi i want to passed my unit test, but i do not know how
Can you help me please
Can you help me please
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',} def coding(s): void=" " for i in s: #indexování if i != ' ': void+=dictionary[i]+" " else: void += ' ' print(void) def decoding(s): void = "" splitstring = a.split(" ") #rozdělení podle mezer for i in splitstring: #indexování void += dictionary2[i] print(void) def selection(f): f=int(input("1. Z ČEŠTINY DO MORSEOVKY || 2. Z MORESOVKY DO ČEŠTINY ")) # menu return f c = 1 d = 0 while(c!="0"): d =selection(d) a=input("ZADEJ TEXT NA ŠIFROVÁNÍ: ") a=a.upper() startUp="" # nevyužívá se ale bez ní program nelze spustit if d==1: # šifrování coding(a) else: # dešifrování decoding(a) c = input(("POKUD CHCTE PROGRAM UKONČIT, ZADEJTE 0 || PRO POKRAČOVÁNÍ ZADEJTE LIBOVOLNÝ ZNAK : "))Unit test
from example import coding from example import decoding from example import selection from example import a import pytest def test_coding(): #test coding for letters A-Z assert test_coding('A') == '.-' assert test_coding('B') == '-...' assert test_coding('C') == '-.-.' assert test_coding('D') == '-..' assert test_coding('E') == '.' assert test_coding('F') == '..-.' assert test_coding('G') == '--.' assert test_coding('H') == '....' assert test_coding('I') == '..' assert test_coding('J') == '.---' assert test_coding('K') == '-.-' assert test_coding('L') == '.-..' assert test_coding('M') == '--' assert test_coding('N') == '-.' assert test_coding('O') == '---' assert test_coding('P') == '.--.' assert test_coding('Q') == '--.-' assert test_coding('R') == '.-.' assert test_coding('S') == '...' assert test_coding('T') == '-' assert test_coding('U') == '..-' assert test_coding('V') == '...-' assert test_coding('W') == '.--' assert test_coding('X') == '-..-' assert test_coding('Y') == '-.--' assert test_coding('Z') == '--..' # test typeerror with pytest.raises(TypeError): test_coding(4) test_coding(True) test_coding("r") def test_decoding() : #test decoding for letters A-Z assert test_decoding('.-') == 'A' assert test_decoding('-...') == 'B' assert test_decoding('-.-.') == 'C' assert test_decoding('-..') == 'D' assert test_decoding('.') == 'E' assert test_decoding('..-.') == 'F' assert test_decoding('--.') == 'G' assert test_decoding('....') == 'H' assert test_decoding('..') == 'I' assert test_decoding('---') == 'J' assert test_decoding('-.-') == 'K' assert test_decoding('.-..') == 'L' assert test_decoding('--') == 'M' assert test_decoding('-.') == 'N' assert test_decoding('---') == 'O' assert test_decoding('.--.') == 'P' assert test_decoding('--.-') == 'Q' assert test_decoding('.-.') == 'R' assert test_decoding('...') == 'S' assert test_decoding('-') == 'T' assert test_decoding('..-') == 'U' assert test_decoding('...-') == 'V' assert test_decoding('.--') == 'W' assert test_decoding('-..-') == 'X' assert test_decoding('-.--') == 'Y' assert test_decoding('--..') == 'Z' def test_selection(): assert test_selection(1) == test_coding(a)