From 5388deca9774e2bc93a8b821f3d4832c03ce9466 Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Wed, 18 Mar 2026 21:43:45 -0500 Subject: [PATCH 01/13] Update lab_1a.py Add my name to lab_1a --- 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..10c85ffb 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 = "Arnav Mittal" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") From 1997c7122e0aefe79ed8506141690dc2680e37cd Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Wed, 18 Mar 2026 21:46:46 -0500 Subject: [PATCH 02/13] Update lab_1a.py Add personal introduction print statement --- 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 10c85ffb..1e7a63da 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -11,6 +11,7 @@ def main(): name = "Arnav Mittal" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") + print(f"I'm a sophomore from Texas! I dream of being a particle physicist.") if __name__ == "__main__": main() From 2169055502f9f44b7d920a7848793d30103ec396 Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Wed, 18 Mar 2026 21:54:20 -0500 Subject: [PATCH 03/13] Add simulated robot change --- labs/lab_1/lab_1a.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/labs/lab_1/lab_1a.py b/labs/lab_1/lab_1a.py index 1e7a63da..4f952828 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -3,6 +3,8 @@ 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 202bee2ac08e2fd61e9c4f535537bb737a50fe42 Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Wed, 18 Mar 2026 22:02:30 -0500 Subject: [PATCH 04/13] Update 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 4f952828..f8f28a56 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -4,7 +4,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 f4856c39e9d2283abde9ae79a9ac01480416970f Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Wed, 18 Mar 2026 22:03:14 -0500 Subject: [PATCH 05/13] Increase robot speed 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 4f952828..cd76109c 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -4,7 +4,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 = 8 # m/s """ def main(): From 3676a50431905c6ef6ac03550fba58c1d40d5bcc Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Wed, 18 Mar 2026 22:18:13 -0500 Subject: [PATCH 06/13] Fixed valid number error --- labs/lab_1/lab_1b.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..313773a7 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -36,14 +36,22 @@ 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 request_sanitized_number(prompt: str) -> float: + 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 = request_sanitized_number("Enter the first number: ") + num2 = request_sanitized_number("Enter the second number: ") operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() # Perform the calculation and display the result From 0377768602cdf1c0cd5a8de259c9de427910b4c6 Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Wed, 18 Mar 2026 22:22:58 -0500 Subject: [PATCH 07/13] Sanitize operation input --- labs/lab_1/lab_1b.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index 313773a7..a2472c30 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -45,6 +45,13 @@ def request_sanitized_number(prompt: str) -> float: except ValueError: print("Invalid input. Please enter a valid number.") +def request_sanitized_operation(prompt: str) -> str: + while True: + operation = input(prompt).strip().lower() + if operation in ["add", "subtract", "multiply", "divide"]: + return operation + print("Invalid input. Please enter add, subtract, multiply, or divide.") + def main(): print(f"===== Simple Calculator =====") @@ -52,8 +59,7 @@ def main(): # Ask the user for sample input num1 = request_sanitized_number("Enter the first number: ") num2 = request_sanitized_number("Enter the second number: ") - operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() - + operation = request_sanitized_operation("Enter the operation (add, subtract, multiply, divide): ") # 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}") From 3cf9ab0f3fb98b718d8308a87ad0cfe04bd39f45 Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Thu, 19 Mar 2026 15:24:12 -0500 Subject: [PATCH 08/13] Added more test cases --- tests/tests_1b.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/tests_1b.py b/tests/tests_1b.py index be6b822d..9e29a8a2 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", -9, 4) == -5 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", -9, 4) == -13 def test_multiplication(): assert simple_calculator("multiply", 5, 3) == 15 # Test for positive numbers From ee3ed8596734d6b615cbe8a83ccbcbdb5ca578f2 Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Thu, 19 Mar 2026 15:26:50 -0500 Subject: [PATCH 09/13] Add GitHub Actions workflow for calculator tests --- .github/workflows/run_test.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 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 From 624a0651eca665a275b750f0d388a334ae6c6924 Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Thu, 19 Mar 2026 15:36:58 -0500 Subject: [PATCH 10/13] tests 1c --- tests/tests_1c.py | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 tests/tests_1c.py diff --git a/tests/tests_1c.py b/tests/tests_1c.py new file mode 100644 index 00000000..60926249 --- /dev/null +++ b/tests/tests_1c.py @@ -0,0 +1,37 @@ +""" +tests_1c.py + +Unit tests for max_subarray_sum in lab_1c.py. +""" + +import pytest +from labs.lab_1.lab_1c import max_subarray_sum + + +def test_typical_case(): + assert max_subarray_sum([-2, 1, -3, 4, -1, 2, 1, -5, 4]) == 6 + + +def test_single_element_positive(): + assert max_subarray_sum([5]) == 5 + + +def test_single_element_negative(): + assert max_subarray_sum([-7]) == -7 + + +def test_all_positive(): + assert max_subarray_sum([1, 2, 3, 4]) == 10 + + +def test_all_negative(): + assert max_subarray_sum([-8, -3, -6, -2, -5, -4]) == -2 + + +def test_contains_zero(): + assert max_subarray_sum([0, -1, 0, 2, 3]) == 5 + + +def test_empty_list(): + with pytest.raises(ValueError, match="Input list cannot be empty."): + max_subarray_sum([]) \ No newline at end of file From fcfc3adbc850a05be0b31b803f8c3998ddce9f18 Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Thu, 19 Mar 2026 15:37:57 -0500 Subject: [PATCH 11/13] run test 1c --- .github/workflows/run_test.yml | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 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..a94f3b6e --- /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 tests/tests_1c.py -v -s + - name: Generate Coverage Report + run: | + coverage report -m \ No newline at end of file From a1db5c37856cea727e283b4a96923c79ea0816ac Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Thu, 19 Mar 2026 15:41:23 -0500 Subject: [PATCH 12/13] Fix max_subarray_sum logic and edge cases --- labs/lab_1/lab_1c.py | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/labs/lab_1/lab_1c.py b/labs/lab_1/lab_1c.py index 40cf98db..44eaacd4 100644 --- a/labs/lab_1/lab_1c.py +++ b/labs/lab_1/lab_1c.py @@ -8,7 +8,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. @@ -19,19 +18,23 @@ def max_subarray_sum(nums: list[int]) -> int: Returns: int: The maximum sum of any contiguous subarray. """ + if len(nums) == 0: + raise ValueError("Input list cannot be empty.") - max_current = max_global = nums[0] - - for num in nums: + max_current = nums[0] + max_global = nums[0] + + 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 + # Example usage: def main(): - nums = [-2,1,-3,4,-1,2,1,-5,4] + nums = [-2, 1, -3, 4, -1, 2, 1, -5, 4] result = max_subarray_sum(nums) print(f"Maximum subarray sum: {result}") From 41bd7a891379d1516c7be75a51e0a3fdf8fee73f Mon Sep 17 00:00:00 2001 From: Arnav-M10 Date: Thu, 19 Mar 2026 15:51:11 -0500 Subject: [PATCH 13/13] tests 1d --- .github/workflows/run_test.yml | 2 +- labs/lab_1/lab_1d.py | 25 ++----------------------- tests/tests_1d.py | 28 ++++++++++++++++++++++++++++ 3 files changed, 31 insertions(+), 24 deletions(-) create mode 100644 tests/tests_1d.py diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index a94f3b6e..e8f35ba0 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -26,7 +26,7 @@ jobs: continue-on-error: true - name: Test with pytest run: | - coverage run -m pytest tests/tests_1b.py tests/tests_1c.py -v -s + coverage run -m pytest tests/tests_1b.py tests/tests_1c.py tests/tests_1d.py -v -s - name: Generate Coverage Report run: | coverage report -m \ No newline at end of file diff --git a/labs/lab_1/lab_1d.py b/labs/lab_1/lab_1d.py index ade4b4a8..02a8e931 100644 --- a/labs/lab_1/lab_1d.py +++ b/labs/lab_1/lab_1d.py @@ -1,14 +1,3 @@ -""" -lab_1d.py - -Given an array of integers `nums` and an integer `target`, return indices of the two numbers such that they add up to `target`. - -You may assume that each input would have exactly one solution, and you may not use the same element twice. - -Derived from LeetCode problem: https://leetcode.com/problems/two-sum/ (leetcode easy) -""" - -# TODO: Find and resolve the bug in the following implementation. Create unit tests to verify your fix. def two_sum(nums: list[int], target: int) -> list[int]: """ Function that takes in a list of integers and a target integer, and returns the indices of the two numbers that add up to the target. @@ -23,18 +12,8 @@ def two_sum(nums: list[int], target: int) -> list[int]: num_to_index = {} for index, num in enumerate(nums): - complement = target + num + complement = target - num if complement in num_to_index: return [num_to_index[complement], index] num_to_index[num] = index - return [] # In case there is no solution, though the problem guarantees one exists. - -# Example usage: -def main(): - nums = [2, 7, 11, 15] - target = 9 - result = two_sum(nums, target) - print(f"Indices of the two numbers that add up to {target}: {result}") - -if __name__ == "__main__": - main() \ No newline at end of file + return [] \ No newline at end of file diff --git a/tests/tests_1d.py b/tests/tests_1d.py new file mode 100644 index 00000000..aaa95e35 --- /dev/null +++ b/tests/tests_1d.py @@ -0,0 +1,28 @@ +""" +tests_1d.py + +Unit tests for two_sum in lab_1d.py. +""" + +import pytest +from labs.lab_1.lab_1d import two_sum + + +def test_basic_case(): + assert two_sum([2, 7, 11, 15], 9) == [0, 1] + + +def test_another_case(): + assert two_sum([3, 2, 4], 6) == [1, 2] + + +def test_with_negatives(): + assert two_sum([-1, -2, -3, -4, -5], -8) == [2, 4] + + +def test_same_number_used_twice(): + assert two_sum([3, 3], 6) == [0, 1] + + +def test_large_numbers(): + assert two_sum([1000000, 500000, 500000], 1000000) == [1, 2] \ No newline at end of file