From 301b460d1614e71a2b72d61d1940273b667ede1f Mon Sep 17 00:00:00 2001 From: odurukkar Date: Sun, 15 Feb 2026 23:46:20 -0500 Subject: [PATCH 01/12] Update lab_1a.py Writing my name --- 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..0262f69b 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 = "Om Durukkar" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") From 8f37f391a7a6e91bc8bcbaf34b7c803500f03620 Mon Sep 17 00:00:00 2001 From: odurukkar Date: Sun, 15 Feb 2026 23:50:43 -0500 Subject: [PATCH 02/12] Update lab_1a.py Added a introduction of myself --- 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 0262f69b..20d90222 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -11,6 +11,7 @@ def main(): name = "Om Durukkar" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") + print("Hello all! My name is Om. I like STEM. My favorite subjects outside and inside of school are calculus, chemistry, computer science (particularly machine learning). I program competitively. I also cook food. I like to camp and enjoy the outdoors with my Scout troop.") if __name__ == "__main__": main() From 57b26cfb2e128ff778fa1c3303eecd3503091956 Mon Sep 17 00:00:00 2001 From: odurukkar <76797165+odurukkar@users.noreply.github.com> Date: Tue, 17 Feb 2026 21:04:21 -0500 Subject: [PATCH 03/12] Add comment for robot speed in lab_1a.py Added a comment about robot speed. --- 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 20d90222..3df380f3 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,6 +3,7 @@ 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 = 5 # m/s """ def main(): From a5d82cbf01bad515696d8efe33386d72cdd79c72 Mon Sep 17 00:00:00 2001 From: odurukkar Date: Wed, 18 Feb 2026 18:02:36 -0500 Subject: [PATCH 04/12] Update lab_1a.py Change from 5 to 3 --- 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 3df380f3..28ad1fd3 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,7 +3,7 @@ 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 = 5 # m/s +This is to simulate a change made on a robot: robot_speed = 3 # m/s """ def main(): From e903ef7b90e3528fae9570396d0ad3f8ad7ae7f3 Mon Sep 17 00:00:00 2001 From: odurukkar Date: Wed, 18 Feb 2026 18:07:36 -0500 Subject: [PATCH 05/12] Update lab_1a.py Change 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 28ad1fd3..141539cd 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,7 +3,7 @@ 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 +This is to simulate a change made on a robot: robot_speed = 8 # m/s """ def main(): From de5d7f395208e297143a5be130a9b44f6784cdcd Mon Sep 17 00:00:00 2001 From: odurukkar <76797165+odurukkar@users.noreply.github.com> Date: Wed, 18 Feb 2026 18:08:51 -0500 Subject: [PATCH 06/12] Change robot speed from 8 m/s to 3 m/s --- 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 141539cd..28ad1fd3 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,7 +3,7 @@ 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 = 8 # m/s +This is to simulate a change made on a robot: robot_speed = 3 # m/s """ def main(): From 9f60c50f181e65f37b9d2f9fc3d01ae06a8d1ab2 Mon Sep 17 00:00:00 2001 From: odurukkar <76797165+odurukkar@users.noreply.github.com> Date: Wed, 18 Feb 2026 18:11:09 -0500 Subject: [PATCH 07/12] Change robot speed from 3 m/s to 5 m/s --- 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 28ad1fd3..3df380f3 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,7 +3,7 @@ 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 +This is to simulate a change made on a robot: robot_speed = 5 # m/s """ def main(): From 0458ec758a90f487cc8017e9c2463fd8ba6ef046 Mon Sep 17 00:00:00 2001 From: odurukkar Date: Wed, 18 Feb 2026 18:13:47 -0500 Subject: [PATCH 08/12] Update lab_1a.py Changed to 8 from 3 --- 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 28ad1fd3..141539cd 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,7 +3,7 @@ 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 +This is to simulate a change made on a robot: robot_speed = 8 # m/s """ def main(): From 66136917f680de5de2f042723a7bf449f3c064f7 Mon Sep 17 00:00:00 2001 From: odurukkar Date: Wed, 18 Feb 2026 23:49:25 -0500 Subject: [PATCH 09/12] Update lab_1b.py added a input_number function --- labs/lab_1/lab_1b.py | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..7df756a4 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -36,14 +36,31 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: raise ValueError("Cannot divide by zero.") else: raise ValueError("Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'.") + +def input_number(prompt: str) -> float: + """ + Helper function to request a number from the user and ensure it's a valid float. + + Args: + prompt (str): The prompt to display to the user. + + Returns: + float: The sanitized number 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 =====") # Ask the user for sample input - num1 = float(input("Enter the first number: ")) - num2 = float(input("Enter the second number: ")) + num1 = input_number("Enter the first number: ") + num2 = input_number("Enter the second number: ") operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() # Perform the calculation and display the result From c3ba07eee464cdfa43d875cf32542b70d7e3b399 Mon Sep 17 00:00:00 2001 From: odurukkar Date: Thu, 19 Feb 2026 12:27:43 -0500 Subject: [PATCH 10/12] changes for the 1.2.4 and 1.2.5 --- ".github\\workflows/run_test.yml" | 32 +++++++++++++++++++++++++++++++ tests/tests_1b.py | 2 ++ 2 files changed, 34 insertions(+) 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/tests/tests_1b.py b/tests/tests_1b.py index be6b822d..30c19c25 100644 --- a/tests/tests_1b.py +++ b/tests/tests_1b.py @@ -11,11 +11,13 @@ def test_addition(): assert simple_calculator("add", 5, 3) == 8 # Test for positive numbers assert simple_calculator("add", -2, 2) == 0 # Test for negative and positive number assert simple_calculator("add", 0, 0) == 0 # Test for zero addition + assert simple_calculator("add", -2, -4) == -6 # Test for negative numbers def test_subtraction(): assert simple_calculator("subtract", 5, 3) == 2 # Test for positive numbers assert simple_calculator("subtract", -2, -2) == 0 # Test for negative numbers assert simple_calculator("subtract", 0, 5) == -5 # Test for zero minuend + assert simple_calculator("subtract", 0, -5) == 5 def test_multiplication(): assert simple_calculator("multiply", 5, 3) == 15 # Test for positive numbers From c59df9d576ae99d8a0071224a3bbb2154bae06e7 Mon Sep 17 00:00:00 2001 From: odurukkar Date: Thu, 19 Feb 2026 15:08:03 -0500 Subject: [PATCH 11/12] new folder of workflow --- .../run_test.yml" => .github/workflows/run_test.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename ".github\\workflows/run_test.yml" => .github/workflows/run_test.yml (100%) diff --git "a/.github\\workflows/run_test.yml" b/.github/workflows/run_test.yml similarity index 100% rename from ".github\\workflows/run_test.yml" rename to .github/workflows/run_test.yml From cdf14b95f531ccc8752337f8238971d238f14bc1 Mon Sep 17 00:00:00 2001 From: odurukkar Date: Thu, 19 Feb 2026 21:51:12 -0500 Subject: [PATCH 12/12] Fix max_subarray_sum and add unit tests --- labs/lab_1/lab_1c.py | 11 ++++++----- tests/test_lab_1c.py | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 5 deletions(-) create mode 100644 tests/test_lab_1c.py diff --git a/labs/lab_1/lab_1c.py b/labs/lab_1/lab_1c.py index 40cf98db..baa500db 100644 --- a/labs/lab_1/lab_1c.py +++ b/labs/lab_1/lab_1c.py @@ -7,8 +7,6 @@ Derived from LeetCode problem: https://leetcode.com/problems/maximum-subarray/ (leetcode medium) """ - -# TODO: Find and resolve the bug in the following implementation. Create unit tests to verify your fix. def max_subarray_sum(nums: list[int]) -> int: """ Function that takes in a list of integers and returns the maximum sum of any contiguous subarray. @@ -20,11 +18,14 @@ def max_subarray_sum(nums: list[int]) -> int: int: The maximum sum of any contiguous subarray. """ + if not nums: + raise ValueError("Input list must contain at least one number.") + 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: + if max_current > max_global: max_global = max_current return max_global @@ -36,4 +37,4 @@ def main(): print(f"Maximum subarray sum: {result}") if __name__ == "__main__": - main() \ No newline at end of file + main() diff --git a/tests/test_lab_1c.py b/tests/test_lab_1c.py new file mode 100644 index 00000000..ca24cbfa --- /dev/null +++ b/tests/test_lab_1c.py @@ -0,0 +1,38 @@ +""" +Unit tests for max_subarray_sum in labs.lab_1.lab_1c. +""" + +import pytest + +from labs.lab_1.lab_1c import max_subarray_sum + + +def test_example_from_prompt(): + # Typical mix of positives and negatives + assert max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6 # [4, -1, 2, 1] + + +def test_all_negative_returns_least_negative(): + assert max_subarray_sum([-8, -3, -6, -2, -5, -4]) == -2 + + +def test_single_element_list(): + assert max_subarray_sum([7]) == 7 + + +def test_all_positive_accumulates_entire_list(): + assert max_subarray_sum([1, 2, 3, 4]) == 10 + + +def test_empty_list_raises_value_error(): + with pytest.raises(ValueError, match="Input list must contain at least one number."): + max_subarray_sum([]) + + +def test_prefix_negative_suffix_positive(): + # Ensures algorithm resets after negative prefix + assert max_subarray_sum([-10, 5, 6]) == 11 + + +if __name__ == "__main__": + pytest.main()