Search code examples
pythonalgorithmuser-interfaceinput

Wrote a UI with inputs in Python- how can I check to make sure they work?


I have to create code for a UI in Python. I basically have 4 options, and each option, of course, will print a result desired. The code is below. I am missing a print line for one, but I asked my instructor about that. What I need to know as well- how can I test my UI code to see if I will get the results I am wanting?

getPackageStatus = True
while getPackageStatus:
    # Options for UI
    print("\nWhat Would You Like to Check Today?")
    print("1. All package statuses and Total Truck mileage")
    print("2. Status of all Packages at a given time")
    print("3. Single package status with a given time")
    print("4. Exit the program")
    # Go through each option, describing outcomes
    option = input("Choose an option (1,2,3, or 4): ")
    # Option 1
    if option == "1":
        for i in range(40):
            print(myHash.search(i + 1) + str(t1.mileage + t2.mileage + t3.mileage))
    # Option 2
    elif option == "2":
        checkTime = input('Please enter a time in the form "00:00:00"')
        hour, minute, second = checkTime.split(":")
        rtime = datetime.timedelta(hours=int(hour), minutes=int(minute), seconds=int(second))
        if checkTime < pkg1.timeLeftHub0:
            pkg1.status = 'At Hub'
        elif checkTime == pkg1.time_delivered:
            pkg1.status = 'Delivered'
        elif checkTime > pkg1.time_delivered:
            pkg1.status = 'Delivered'
        else:
            pkg1.status = 'En Route'
        # Need help writing the print statement that will print out all pkg1.status for all packages. I know it will involve strings and a myHash.search method so each package ID will be associated with its status at checkTime
    # Option 3
    elif option == "3":
        checkPackage = input('Please enter a package using its package ID')
        for package_id in checkPackage:
            pkg1 = myHash.search(package_id)
        checkTime = input('Please enter a time in the form "00:00:00"')
        hour, minute, second = checkTime.split(":")
        rtime = datetime.timedelta(hours=int(hour), minutes=int(minute), seconds=int(second))
        if checkTime < pkg1.timeLeftHub0:
            pkg1.status = 'At Hub'
            print(str(pkg1.package_id) + 'package status at ' + str(checkTime) + ' = ' + str(pkg1.status))
        elif checkTime == pkg1.time_delivered:
            pkg1.status = 'Delivered'
            print(str(pkg1.package_id) + 'package status at ' + str(checkTime) + ' = ' + str(pkg1.status))
        elif checkTime > pkg1.time_delivered:
            pkg1.status = 'Delivered'
            print(str(pkg1.package_id) + 'package status at ' + str(checkTime) + ' = ' + str(pkg1.status))
        else:
            pkg1.status = 'En Route'
            print(str(pkg1.package_id) + 'package status at ' + str(checkTime) + ' = ' + str(pkg1.status))
    # Option 4
    elif option == "4":
        getPackageStatus = False

I have no idea how to test this and can't find anything online


Solution

  • Testing a UI isn't easy.

    Basically you have to test each option (1, 2, 3 and 4) and related subsections with a known answer.

    As an example, if you input '1', you should be able to read all the 40 rows of output and check if the result is correct.

    You MUST also test the UI with wrong input (i.e. '8', 'K', and any kind of key you may find on your keyboard). If a wrong input is not handled in the right way, the program may crash or enter a dangerous situation. What happens if, at selection '2', you input "ga:me:ov:er"?