Python Forum
Homework Python unit test
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Homework Python unit test
#1
Hi i want to passed my unit test, but i do not know how
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)

Attached Files

.py   example.py (Size: 1.57 KB / Downloads: 200)
.py   example_test (1).py (Size: 2.46 KB / Downloads: 197)
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,986 Oct-12-2021, 10:12 AM
Last Post: buran
  CyperSecurity Using Python HomeWork ward1995 1 2,591 Jul-08-2021, 03:55 PM
Last Post: buran
Exclamation urgent , Python homework alm 2 3,319 May-09-2021, 11:19 AM
Last Post: Yoriz
  Homework with python Johnsonmfw 1 2,301 Sep-20-2020, 04:03 AM
Last Post: ndc85430
  Unit Testing is not showing Test case result mbilalshafiq 2 2,573 Jul-01-2020, 08:50 PM
Last Post: mbilalshafiq
  Python Homework Help *Urgent GS31 2 3,367 Nov-24-2019, 01:41 PM
Last Post: ichabod801
  Help with Unit Tests pdub787 3 4,016 Nov-20-2019, 07:45 PM
Last Post: ndc85430
  Python Homework Question OrcDroid123 1 3,162 Sep-01-2019, 08:44 AM
Last Post: buran
  Python homework / functions sunhyunshine 1 3,085 May-11-2019, 05:37 PM
Last Post: MrTheOne
  python homework help ASAP gk34332 1 3,614 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