|
| 1 | +import subprocess |
| 2 | + |
| 3 | + |
| 4 | +def runTest (file, inText): |
| 5 | + if file =="order": |
| 6 | + res = subprocess.run("python " + file + ".py", input=inText, capture_output=True, text=True, shell=True) |
| 7 | + return res.stdout |
| 8 | + |
| 9 | + if file == "pizzaReceipt": |
| 10 | + res = subprocess.run("python -c \"from pizzaReceipt import *; generateReceipt([" +inText+ "])\"", capture_output=True, text=True, shell= True) |
| 11 | + return res.stdout |
| 12 | + |
| 13 | + |
| 14 | +def equalWithoutSpaces(expected, student): |
| 15 | + expected = expected.replace(" ", "") |
| 16 | + expected = expected.replace("\t", "") |
| 17 | + student = student.replace(" ", "") |
| 18 | + student = student.replace("\t", "") |
| 19 | + return expected == student |
| 20 | + |
| 21 | + |
| 22 | + |
| 23 | +# --------------- Test 1 - No Order--------------- |
| 24 | + |
| 25 | +inputString = "" |
| 26 | +studentOutput = runTest("pizzaReceipt", inputString) |
| 27 | +expectedOutput = "You did not order anything\n" |
| 28 | + |
| 29 | +# Compare studentOutput to expectedOutput |
| 30 | +if studentOutput == expectedOutput: |
| 31 | + print("Test 1 Passed. (Receipt for empty order)") |
| 32 | +else: |
| 33 | + print("Test 1 Failed. (Receipt for empty order)") |
| 34 | + |
| 35 | +#print(studentOutput) |
| 36 | + |
| 37 | +# --------------- Test 2 - List of Orders--------------- |
| 38 | + |
| 39 | +inputString = "('L', ['HAM', 'BACON', 'ONION', 'TOMATO']), ('S', ['PEPPERONI', 'SAUSAGE', 'CHICKEN', 'HAM']), ('L', ['BROCCOLI', 'CHICKEN', 'ONION'])" |
| 40 | +studentOutput = runTest("pizzaReceipt", inputString) |
| 41 | +expectedOutput = "Your order: \nPizza 1: L 11.99\n- HAM\n- BACON\n- ONION\n- TOMATO\nExtra Topping (L) 1.00\n" |
| 42 | +expectedOutput += "Pizza 2: S 7.99\n- PEPPERONI\n- SAUSAGE\n- CHICKEN\n- HAM\nExtra Topping (S) 0.50\n" |
| 43 | +expectedOutput += "Pizza 3: L 11.99\n- BROCCOLI\n- CHICKEN\n- ONION\nTax: 4.35\nTotal: 37.82\n" |
| 44 | + |
| 45 | +# Compare studentOutput to expectedOutput |
| 46 | +#if studentOutput == expectedOutput: |
| 47 | +if equalWithoutSpaces(expectedOutput, studentOutput): |
| 48 | + print("Test 2 Passed. (Receipt for empty order of 3 pizzas)") |
| 49 | +else: |
| 50 | + print("Test 2 Failed. (Receipt for empty order of 3 pizzas)") |
| 51 | + |
| 52 | + |
| 53 | +# --------------- Test 3 - List of Orders--------------- |
| 54 | + |
| 55 | +inputString = "('XL', ['GREEN PEPPER', 'HOT PEPPER', 'MUSHROOM', 'ONION', 'SPINACH']), ('L', ['PEPPERONI', 'ONION', 'OLIVE', 'MUSHROOM']), ('L', ['PINEAPPLE', 'HAM']), ('M', ['GROUND BEEF', 'TOMATO', 'ONION', 'SPINACH'])" |
| 56 | +studentOutput = runTest("pizzaReceipt", inputString) |
| 57 | +expectedOutput = "Your order: \nPizza 1: XL 13.99\n- GREEN PEPPER\n- HOT PEPPER\n- MUSHROOM\n- ONION\n- SPINACH\nExtra Topping (XL) 1.25\n" |
| 58 | +expectedOutput += "Extra Topping (XL) 1.25\nPizza 2: L 11.99\n- PEPPERONI\n- ONION\n- OLIVE\n- MUSHROOM\n" |
| 59 | +expectedOutput += "Extra Topping (L) 1.00\nPizza 3: L 11.99\n- PINEAPPLE\n- HAM\nPizza 4: M 9.99\n" |
| 60 | +expectedOutput += "- GROUND BEEF\n- TOMATO\n- ONION\n- SPINACH\nExtra Topping (M) 0.75\nTax: 6.79\nTotal: 59.00\n" |
| 61 | + |
| 62 | +# Compare studentOutput to expectedOutput |
| 63 | +if equalWithoutSpaces(expectedOutput, studentOutput): |
| 64 | + print("Test 3 Passed. (Receipt for empty order of 4 pizzas)") |
| 65 | +else: |
| 66 | + print("Test 3 Failed. (Receipt for empty order of 4 pizzas)") |
| 67 | + |
| 68 | +# --------------- Test 4 - Find Specific Values in Output --------------- |
| 69 | + |
| 70 | +studentOutput = runTest("order", "Yes\nL\nHAM\nX\nNo\n") |
| 71 | + |
| 72 | +if studentOutput.find("13.55") != -1: |
| 73 | + print("Test 4 Passed. (Ordering system for order of 1 pizza)") |
| 74 | +else: |
| 75 | + print("Test 4 Failed. (Ordering system for order of 1 pizza)") |
| 76 | + |
| 77 | +#print(studentOutput) |
| 78 | + |
| 79 | +# --------------- Test 5 - Find Specific Values in Output--------------- |
| 80 | + |
| 81 | +studentOutput = runTest("order", "Yes\nmedium\nM\nLIST\npepperoni\nonion\nmushroom\nhot pepper\ntomato\nX\nq\n") |
| 82 | + |
| 83 | +if studentOutput.find("\"X\"\n('") != -1 and studentOutput.count("Choose a size:") == 2 and studentOutput.count("Type in one of our toppings") == 7 and studentOutput.find("1.49") != -1 and studentOutput.find("12.98") != -1: |
| 84 | + print("Test 5 Passed. (Ordering system with typo and use of LIST)") |
| 85 | +else: |
| 86 | + |
| 87 | + print("Test 5 Failed. (Ordering system with typo and use of LIST)") |
| 88 | + |
| 89 | +print() |
| 90 | +print(studentOutput.find("\"X\"\n('") != -1) |
| 91 | +print(studentOutput.count("Choose a size:") == 2) |
| 92 | +print(studentOutput.count("Type in one of our toppings") == 7) |
| 93 | +print(studentOutput.find("1.49") != -1) |
| 94 | +print(studentOutput.find("12.98") != -1) |
| 95 | +print() |
| 96 | + |
| 97 | +# --------------- Find Specific Values in Output --------------- |
| 98 | + |
| 99 | +studentOutput = runTest("order", "y\nm\nsausage\nbacon\nonion\nX\ny\nXl\nchicken\ntomato\nspinach\nmushroom\nx\ny\nm\nolive\nbroccoli\nhot pepper\ngreen pepper\nx\nno\n") |
| 100 | + |
| 101 | +if studentOutput.count("Type in one of our toppings") == 14 and studentOutput.find("4.68") != -1 and studentOutput.find("40.65") != -1: |
| 102 | + print("Test 6 Passed. (Ordering system for order of 3 pizzas)") |
| 103 | +else: |
| 104 | + print("Test 6 Failed. (Ordering system for order of 3 pizzas)") |
| 105 | + |
| 106 | +# print(studentOutput) |
| 107 | +# print(expectedOutput) |
| 108 | +# -------------------------------- |
| 109 | + |
| 110 | + |
| 111 | + |
| 112 | + |
0 commit comments