From cea3fba36ff73d1355d194264dd21895f25f243f Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Thu, 9 Apr 2026 10:01:27 -0700 Subject: [PATCH] Add test cases --- .../notes-and-examples/2026.04.08/homework.py | 23 +++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/shared/notes-and-examples/2026.04.08/homework.py b/shared/notes-and-examples/2026.04.08/homework.py index 55a10c5..e50c407 100644 --- a/shared/notes-and-examples/2026.04.08/homework.py +++ b/shared/notes-and-examples/2026.04.08/homework.py @@ -12,3 +12,26 @@ # Start with the "innermost" expression and work backwards (this is the recursion part) # # For help, email me@bchen.dev + +# Use this function definition: +def rpn(expression: list[str]) -> int: + return 0 + + +# The following test cases should pass (please copy this into your code): +tests = [ + (["3", "2", "+"], 5), + (["3", "4", "*"], 12), + (["3", "4", "2", "+", "*"], 18), + ([], 0), + (["50", "2", "/"], 25), + (["5", "2", "/"], 2), # for division, cast to int using int(num) + (["5", "4", "3", "-", "*"], 5), +] +for case in tests: + result = rpn(case[0]) + expected = case[1] + if result == expected: + print(f"PASS: expected {expected}, got {result} for {case[0]}") + else: + print(f"FAIL: expected {expected}, got {result} for {case[0]}")