From 4c395d78aaf9d55abf3a175af923dcc21e86e138 Mon Sep 17 00:00:00 2001 From: juha1ee <167262024+juha1ee@users.noreply.github.com> Date: Wed, 11 Feb 2026 20:03:17 -0500 Subject: [PATCH 01/13] add name to lab_1a.py --- labs/lab_1/lab_1a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 9d15ec83..f81f0120 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -8,7 +8,7 @@ def main(): print("Hello World!") - name = "" # TODO: Insert your name between the double quotes + name = "Juha Lee" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") From 2de856ab88a89f0c2e0a000bb7a136974a2f82e2 Mon Sep 17 00:00:00 2001 From: juha1ee <167262024+juha1ee@users.noreply.github.com> Date: Wed, 11 Feb 2026 20:08:10 -0500 Subject: [PATCH 02/13] practice edit to lab_1a.py --- labs/lab_1/lab_1a.py | 1 + 1 file changed, 1 insertion(+) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index f81f0120..1173dee0 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -11,6 +11,7 @@ def main(): name = "Juha Lee" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") + print("Hi, I'm Juha and I'm a junior from New Jersey.") if __name__ == "__main__": main() From 09ca6f3aed7f1aeaa2b75d49e4947e013c422e2d Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Wed, 11 Feb 2026 20:15:45 -0500 Subject: [PATCH 03/13] add comment about robot speed variable --- labs/lab_1/lab_1a.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 1173dee0..74c83abc 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -1,6 +1,10 @@ """ lab_1a.py +This is to simulate a change made on a robot: robot_speed = 5 # m/s + + + The first lab in the BWSI CSS course. To complete this lab, fill out the variable on line 10 with your name. Then, save the code, add it to the staging area, and commit it to the Git tree. """ From 13f361d58ec4f6126eb7bdc544d56ddfc9b15e7f Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Wed, 11 Feb 2026 20:23:12 -0500 Subject: [PATCH 04/13] change robot speed from 5 to 3 --- labs/lab_1/lab_1a.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 74c83abc..fcd7a81b 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -1,12 +1,12 @@ """ lab_1a.py -This is to simulate a change made on a robot: robot_speed = 5 # m/s - - The first lab in the BWSI CSS course. To complete this lab, fill out the variable on line 10 with your name. Then, save the code, add it to the staging area, and commit it to the Git tree. + + +This is to simulate a change made on a robot: robot_speed = 3 # m/s """ def main(): From 3f3de47f4b05b6eaeed7e00239067b2434128441 Mon Sep 17 00:00:00 2001 From: juha1ee <167262024+juha1ee@users.noreply.github.com> Date: Wed, 11 Feb 2026 20:27:16 -0500 Subject: [PATCH 05/13] change speed from 5 to 8 --- labs/lab_1/lab_1a.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 74c83abc..9b68a5b1 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -1,7 +1,7 @@ """ lab_1a.py -This is to simulate a change made on a robot: robot_speed = 5 # m/s +This is to simulate a change made on a robot: robot_speed = 8 # m/s From 928c2f1537e2cacd1884684310633e2282f2ec76 Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Mon, 16 Feb 2026 14:36:47 -0500 Subject: [PATCH 06/13] Update lab_1b.py --- labs/lab_1/lab_1b.py | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..6f10bd57 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -37,6 +37,20 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: else: raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") +def request_sanitized_number(prompt: str) -> float: + """ + Function to request a sanitized number for the operation + + Returns: + float: the sanitized numeric input by the user + """ + while True: + try: + number = float(input(prompt)) + return number + except ValueError: + print("Invalid input. Please enter a valid number.") + def main(): print(f"===== Simple Calculator =====") From 3f2a342d9ebc400087876a282afd40cb61037990 Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Mon, 16 Feb 2026 14:39:45 -0500 Subject: [PATCH 07/13] add user input sanitization --- labs/lab_1/lab_1b.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index 6f10bd57..71019f08 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -42,7 +42,7 @@ def request_sanitized_number(prompt: str) -> float: Function to request a sanitized number for the operation Returns: - float: the sanitized numeric input by the user + float: The sanitized numeric input by the user """ while True: try: From e0d1fca4ccaf64f137dcfce30011801e26f78ea0 Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Mon, 16 Feb 2026 14:55:26 -0500 Subject: [PATCH 08/13] add sanitization for operation input --- labs/lab_1/lab_1b.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index 71019f08..9237cae0 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -29,13 +29,11 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: return num1 - num2 elif operation == "multiply": return num1 * num2 - elif operation == "divide": + else: if num2 != 0: return num1 / num2 else: raise ValueError("Cannot divide by zero.") - else: - raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") def request_sanitized_number(prompt: str) -> float: """ @@ -51,14 +49,29 @@ def request_sanitized_number(prompt: str) -> float: except ValueError: print("Invalid input. Please enter a valid number.") +def request_sanitized_operation(prompt: str) -> str: + """ + Function to request a sanitized and valid operation + + Returns: + str: The sanitized operation by the user + """ + operation = input(prompt).strip().lower() + while True: + if ((operation != "add") and (operation != "subtract") and (operation != "multiply") and (operation!= "divide")): + print("Invalid input. Please enter a valid operation.") + operation = input(prompt).strip().lower() + else: + return operation + def main(): print(f"===== Simple Calculator =====") # Ask the user for sample input - num1 = float(input("Enter the first number: ")) - num2 = float(input("Enter the second number: ")) - operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() + num1 = request_sanitized_number("Enter the first number: ") + num2 = request_sanitized_number("Enter the second number: ") + operation = request_sanitized_operation("Enter the operation (add, subtract, multiply, divide): ").strip().lower() # Perform the calculation and display the result result = simple_calculator(operation, num1, num2) From d1d4fac040af1f4b4ea225cb501f7c9584d58e2a Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Mon, 16 Feb 2026 15:24:22 -0500 Subject: [PATCH 09/13] add unit tests for simple_calculator --- .github/workflows/run_test.yml | 32 +++++++++++++++++++++++++++++ labs/lab_1/lab_1b.py | 37 +++++++++++----------------------- 2 files changed, 44 insertions(+), 25 deletions(-) create mode 100644 .github/workflows/run_test.yml diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml new file mode 100644 index 00000000..c45bcbfc --- /dev/null +++ b/.github/workflows/run_test.yml @@ -0,0 +1,32 @@ +name: simple_calculator unit test + +on: [push] + +jobs: + build: + runs-on: ubuntu-latest + strategy: + matrix: + python-version: ["3.10"] + + steps: + - uses: actions/checkout@v3 + - name: Set up Python ${{ matrix.python-version }} + uses: actions/setup-python@v4 + with: + python-version: ${{ matrix.python-version }} + - name: Install dependencies + run: | + python -m pip install --upgrade pip + if [ -f requirements.txt ]; then pip install -r requirements.txt; fi + - name: Lint with Ruff + run: | + pip install ruff + ruff --format=github --target-version=py310 . + continue-on-error: true + - name: Test with pytest + run: | + coverage run -m pytest tests/tests_1b.py -v -s + - name: Generate Coverage Report + run: | + coverage report -m \ No newline at end of file diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index 9237cae0..e710178b 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -29,11 +29,13 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: return num1 - num2 elif operation == "multiply": return num1 * num2 - else: + elif operation == "divide": if num2 != 0: return num1 / num2 else: raise ValueError("Cannot divide by zero.") + else: + raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") def request_sanitized_number(prompt: str) -> float: """ @@ -48,35 +50,20 @@ def request_sanitized_number(prompt: str) -> float: return number except ValueError: print("Invalid input. Please enter a valid number.") - -def request_sanitized_operation(prompt: str) -> str: - """ - Function to request a sanitized and valid operation - - Returns: - str: The sanitized operation by the user - """ - operation = input(prompt).strip().lower() - while True: - if ((operation != "add") and (operation != "subtract") and (operation != "multiply") and (operation!= "divide")): - print("Invalid input. Please enter a valid operation.") - operation = input(prompt).strip().lower() - else: - return operation - + def main(): - - print(f"===== Simple Calculator =====") + print("===== Simple Calculator =====") - # Ask the user for sample input + # Ask the user for sample input num1 = request_sanitized_number("Enter the first number: ") num2 = request_sanitized_number("Enter the second number: ") - operation = request_sanitized_operation("Enter the operation (add, subtract, multiply, divide): ").strip().lower() - - # Perform the calculation and display the result - result = simple_calculator(operation, num1, num2) - print(f"The result of {operation}ing {num1} and {num2} is: {result}") + operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() + try: + result = simple_calculator(operation, num1, num2) + print(f"The result of {operation}ing {num1} and {num2} is: {result}") + except ValueError as e: + print(f"Error: {e}") if __name__ == "__main__": main() From 49798415c81a815932d0653e26eccc49b97d7e8a Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Mon, 16 Feb 2026 15:54:17 -0500 Subject: [PATCH 10/13] add unit tests for lab_1c --- .github/workflows/run_test.yml | 3 +++ tests/test_1c.py | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+) create mode 100644 tests/test_1c.py diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index c45bcbfc..fcb5171d 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -27,6 +27,9 @@ jobs: - name: Test with pytest run: | coverage run -m pytest tests/tests_1b.py -v -s + - name: Test with pytest + run: | + coverage run -m pytest tests/tests.1c.py -v -s - name: Generate Coverage Report run: | coverage report -m \ No newline at end of file diff --git a/tests/test_1c.py b/tests/test_1c.py new file mode 100644 index 00000000..f289608b --- /dev/null +++ b/tests/test_1c.py @@ -0,0 +1,32 @@ +""" +test_1c.py + +This module contains unit tests for the maximum subarray sum function defined in lab_1c.py. +""" + +import pytest +from labs.lab_1.lab_1c import max_subarray_sum + +def test_example(): + assert max_subarray_sum([-2,1,-3,4,-1,2,1,-5,4]) == 6 # test given example + +def test_single_positive(): + assert max_subarray_sum([3]) == 3 # test a single positive number + +def test_single_negative(): + assert max_subarray_sum([-5]) == -5 # test a single negative number + +def test_all_positive(): + assert max_subarray_sum([1, 5, 7, 2]) == 15 # test a list of all positives + +def test_all_negative(): + assert max_subarray_sum([-3, -2, -7]) == -2 # test a list of all negatives + +def test_with_zero(): + assert max_subarray_sum([-2, -5, 0]) == 0 # test a zero in the list + +def test_all_zeroes(): + assert max_subarray_sum([0, 0, 0]) == 0 # test a list of all zeroes + +if __name__ == "__main__": + pytest.main() \ No newline at end of file From 35f01a2baf9e910eb0237e7219ec05340214880b Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Mon, 16 Feb 2026 15:56:38 -0500 Subject: [PATCH 11/13] fix file name and misspellings --- .github/workflows/run_test.yml | 2 +- tests/{test_1c.py => tests_1c.py} | 0 2 files changed, 1 insertion(+), 1 deletion(-) rename tests/{test_1c.py => tests_1c.py} (100%) diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index fcb5171d..6c1b8047 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -29,7 +29,7 @@ jobs: coverage run -m pytest tests/tests_1b.py -v -s - name: Test with pytest run: | - coverage run -m pytest tests/tests.1c.py -v -s + coverage run -m pytest tests/tests_1c.py -v -s - name: Generate Coverage Report run: | coverage report -m \ No newline at end of file diff --git a/tests/test_1c.py b/tests/tests_1c.py similarity index 100% rename from tests/test_1c.py rename to tests/tests_1c.py From babac6194b2588476a87a3331079b0296367ebbe Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Mon, 16 Feb 2026 15:58:27 -0500 Subject: [PATCH 12/13] fix lab_c --- labs/lab_1/lab_1c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1c.py b/labs/lab_1/lab_1c.py index 40cf98db..cad734ff 100644 --- a/labs/lab_1/lab_1c.py +++ b/labs/lab_1/lab_1c.py @@ -22,7 +22,7 @@ def max_subarray_sum(nums: list[int]) -> int: max_current = max_global = nums[0] - for num in nums: + for num in nums[1:]: max_current = max(num, max_current + num) if max_current < max_global: max_global = max_current From 9a7d3d0b999e2aeeefdaf134afc407d09860562a Mon Sep 17 00:00:00 2001 From: Juha Lee <167262024+juha1ee@users.noreply.github.com> Date: Mon, 16 Feb 2026 15:59:54 -0500 Subject: [PATCH 13/13] fix lab_c again --- labs/lab_1/lab_1c.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1c.py b/labs/lab_1/lab_1c.py index cad734ff..b1495473 100644 --- a/labs/lab_1/lab_1c.py +++ b/labs/lab_1/lab_1c.py @@ -24,7 +24,7 @@ def max_subarray_sum(nums: list[int]) -> int: for num in nums[1:]: max_current = max(num, max_current + num) - if max_current < max_global: + if max_current > max_global: max_global = max_current return max_global