From beb2e2cb99225fba4d9b60d8c06d1c8641db82b3 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Mon, 23 Mar 2026 00:30:54 -0500 Subject: [PATCH 01/13] Added profile name Commit 1 file to main --- 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..34a39457 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 = "Yasho" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") From e9cb1ff92ef3e8564898774023bfe62026172c2f Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Mon, 23 Mar 2026 00:56:28 -0500 Subject: [PATCH 02/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 34a39457..5f2cfbc4 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -11,6 +11,6 @@ def main(): name = "Yasho" # TODO: Insert your name between the double quotes print(f"{name}, Welcome to the CSS course!") - + print(f"I'm {name} and a fun fact about me is that I like to break my record on solving Rubik's Cube!") if __name__ == "__main__": main() From 06ab688eb26fbd0c909e1c12f31665743a747956 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Mon, 23 Mar 2026 01:21:39 -0500 Subject: [PATCH 03/13] Add comment about Robot speed variable Added a comment explaining the variable --- 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 5f2cfbc4..cf19cf91 100644 --- a/labs/lab_1/lab_1a.py +++ b/labs/lab_1/lab_1a.py @@ -1,5 +1,6 @@ """ 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 aaf3301af7abbe25eaabfe38013b33923da307bd Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Tue, 24 Mar 2026 05:35:27 -0500 Subject: [PATCH 04/13] Update lab_1b.py Fixed for input validations and non zero divisor --- labs/lab_1/lab_1b.py | 31 ++++++++++++++++++++++++++----- 1 file changed, 26 insertions(+), 5 deletions(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index e58dd957..ed859111 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -8,6 +8,22 @@ and prints the result to the terminal window. """ +def request_sanitized_number(prompt: str) -> float: + """Helper function to request a number from the user and ensure it's a valid float.""" + while True: + try: + return float(input(prompt)) + except ValueError: + print("Invalid input. Please enter a valid number.") + +def request_nonzero_number(prompt: str) -> float: + """Helper function to request a non-zero number from the user.""" + while True: + num = request_sanitized_number(prompt) + if num != 0: + return num + else: + print("Zero is not allowed. Please enter a non-zero number.") def simple_calculator(operation: str, num1: float, num2: float) -> float: """ @@ -42,14 +58,19 @@ 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: ") operation = input("Enter the operation (add, subtract, multiply, divide): ").strip().lower() + if operation == "divide": + num2 = request_nonzero_number("Enter the second number (non-zero for division): ") + else: + num2 = request_sanitized_number("Enter the second number: ") # 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}") - + 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 09c1590ad9edca1687d8dc7ed25654a3434c7d63 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Tue, 24 Mar 2026 06:18:44 -0500 Subject: [PATCH 05/13] Update tests_1b.py --- tests/tests_1b.py | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tests/tests_1b.py b/tests/tests_1b.py index be6b822d..a317dba1 100644 --- a/tests/tests_1b.py +++ b/tests/tests_1b.py @@ -37,5 +37,23 @@ def test_invalid_operation(): with pytest.raises(ValueError, match="Invalid operation. Please choose from 'add', 'subtract', 'multiply', or 'divide'."): simple_calculator("", 5, 3) # Test for empty operation +def test_operation_case_insensitivity(): + assert simple_calculator("ADD", 5, 3) == 8 # Test for uppercase operation + assert simple_calculator("Subtract", 5, 3) == 2 # Test for mixed case operation + assert simple_calculator("MULTIPLY", 5, 3) == 15 # Test for uppercase operation + assert simple_calculator("DIVIDE", 6, 3) == 2 # Test for uppercase operation + +def test_operation_with_whitespace(): + assert simple_calculator(" add ", 5, 3) == 8 # Test for operation with leading and trailing whitespace + assert simple_calculator(" subtract ", 5, 3) == 2 # Test for operation with leading and trailing whitespace + assert simple_calculator(" multiply ", 5, 3) == 15 # Test for operation with leading and trailing whitespace + assert simple_calculator(" divide ", 6, 3) == 2 # Test for operation with leading and trailing whitespace + +def test_operation_with_non_numeric_input(): + with pytest.raises(ValueError): + simple_calculator("add", "five", 3) # Test for non-numeric input for num1 + with pytest.raises(ValueError): + simple_calculator("subtract", 5, "three") # Test for non-numeric input for num2 + if __name__ == "__main__": pytest.main() \ No newline at end of file From 16ef8c32d5601d80b497d6e59300da4e49e35ace Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Tue, 24 Mar 2026 06:30:10 -0500 Subject: [PATCH 06/13] Fix for case sensitive of perators Addressed failed test cases --- labs/lab_1/lab_1b.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index ed859111..d4a9e710 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -38,7 +38,8 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: Returns: float: The result of the operation. """ - + operation = operation.strip().lower() # Normalize the operation string + if operation == "add": return num1 + num2 elif operation == "subtract": From 5ece1837378666a2132b8b6064f823666926c489 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Tue, 24 Mar 2026 10:13:59 -0500 Subject: [PATCH 07/13] Added run_test.yml Performing assignment under this branch as tests/simple_calculator has issues --- .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 4ba062aeeb1025e077816dfcc9587f8e34e80649 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Tue, 24 Mar 2026 21:46:43 -0500 Subject: [PATCH 08/13] Tested white spaces Case sensitive and white space scenarios --- .vscode/settings.json | 3 +++ labs/lab_1/lab_1b.py | 37 +++++++++---------------------- tests/{tests_1b.py => test_1b.py} | 3 ++- 3 files changed, 16 insertions(+), 27 deletions(-) create mode 100644 .vscode/settings.json rename tests/{tests_1b.py => test_1b.py} (96%) diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..c9ebf2d2 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "python-envs.defaultEnvManager": "ms-python.python:system" +} \ No newline at end of file diff --git a/labs/lab_1/lab_1b.py b/labs/lab_1/lab_1b.py index ed859111..628ace46 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -8,22 +8,6 @@ and prints the result to the terminal window. """ -def request_sanitized_number(prompt: str) -> float: - """Helper function to request a number from the user and ensure it's a valid float.""" - while True: - try: - return float(input(prompt)) - except ValueError: - print("Invalid input. Please enter a valid number.") - -def request_nonzero_number(prompt: str) -> float: - """Helper function to request a non-zero number from the user.""" - while True: - num = request_sanitized_number(prompt) - if num != 0: - return num - else: - print("Zero is not allowed. Please enter a non-zero number.") def simple_calculator(operation: str, num1: float, num2: float) -> float: """ @@ -39,6 +23,12 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: float: The result of the operation. """ + print(f"===== Simple Calculator inside func call =====") + + operation = operation.strip().lower() # Normalize the operation string + + if not isinstance(num1, (int, float)) or not isinstance(num2, (int, float)): + raise ValueError("Both num1 and num2 must be numeric values.") if operation == "add": return num1 + num2 elif operation == "subtract": @@ -58,19 +48,14 @@ def main(): print(f"===== Simple Calculator =====") # Ask the user for sample input - num1 = request_sanitized_number("Enter the first number: ") + 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() - if operation == "divide": - num2 = request_nonzero_number("Enter the second number (non-zero for division): ") - else: - num2 = request_sanitized_number("Enter the second number: ") # Perform the calculation and display the result - 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}") + result = simple_calculator(operation, num1, num2) + print(f"The result of {operation}ing {num1} and {num2} is: {result}") + if __name__ == "__main__": main() diff --git a/tests/tests_1b.py b/tests/test_1b.py similarity index 96% rename from tests/tests_1b.py rename to tests/test_1b.py index a317dba1..57bd588a 100644 --- a/tests/tests_1b.py +++ b/tests/test_1b.py @@ -2,6 +2,7 @@ tests_1b.py This module contains unit tests for the simple_calculator function defined in lab_1b.py. +The tests cover various scenarios for addition, subtraction, multiplication, and division, """ import pytest @@ -51,7 +52,7 @@ def test_operation_with_whitespace(): def test_operation_with_non_numeric_input(): with pytest.raises(ValueError): - simple_calculator("add", "five", 3) # Test for non-numeric input for num1 + simple_calculator("add", "five", 3) # Test for non-numeric input for num1 with pytest.raises(ValueError): simple_calculator("subtract", 5, "three") # Test for non-numeric input for num2 From 6831dd5ee09243a315739f6fa697bb1118e05c4b Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Tue, 24 Mar 2026 22:31:14 -0500 Subject: [PATCH 09/13] updated comments Commit for other test cases --- tests/test_1b.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_1b.py b/tests/test_1b.py index 57bd588a..889dc7eb 100644 --- a/tests/test_1b.py +++ b/tests/test_1b.py @@ -2,7 +2,7 @@ tests_1b.py This module contains unit tests for the simple_calculator function defined in lab_1b.py. -The tests cover various scenarios for addition, subtraction, multiplication, and division, +The tests cover various scenarios for addition, subtraction, multiplication, and division operations """ import pytest From fc3b49f13cc06a325c899e55378a8509e5b7a4d0 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Wed, 25 Mar 2026 00:31:14 -0500 Subject: [PATCH 10/13] added permissions Added permissions --- .github/workflows/run_test.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index c45bcbfc..f5275640 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -1,4 +1,7 @@ name: simple_calculator unit test + +permissions: + actions: write on: [push] From c3468a6831e7f2eaaf84ab3893a80421a065a9f0 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Wed, 25 Mar 2026 00:57:31 -0500 Subject: [PATCH 11/13] updated run test yaml Updated run test yaml --- tests/test_1b.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/test_1b.py b/tests/test_1b.py index 889dc7eb..c53e8338 100644 --- a/tests/test_1b.py +++ b/tests/test_1b.py @@ -3,6 +3,7 @@ This module contains unit tests for the simple_calculator function defined in lab_1b.py. The tests cover various scenarios for addition, subtraction, multiplication, and division operations +including edge cases such as division by zero and invalid operations. The tests are implemented using the pytest framework. Dummy comment to make commit """ import pytest From 7f3d61dbaa714ed89b43f798df887afda4aa1f24 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Wed, 25 Mar 2026 01:12:11 -0500 Subject: [PATCH 12/13] removed comments removed print statements --- .github/workflows/run_test.yml | 2 +- labs/lab_1/lab_1b.py | 4 ---- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index f5275640..1dedf219 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -29,7 +29,7 @@ jobs: continue-on-error: true - name: Test with pytest run: | - coverage run -m pytest tests/tests_1b.py -v -s + coverage run -m pytest tests/test_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 628ace46..4cf42771 100644 --- a/labs/lab_1/lab_1b.py +++ b/labs/lab_1/lab_1b.py @@ -23,8 +23,6 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: float: The result of the operation. """ - print(f"===== Simple Calculator inside func call =====") - operation = operation.strip().lower() # Normalize the operation string if not isinstance(num1, (int, float)) or not isinstance(num2, (int, float)): @@ -45,8 +43,6 @@ def simple_calculator(operation: str, num1: float, num2: float) -> float: 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: ")) From 263ae983828ab2ae5b016c3dbb0e98dae31c95a5 Mon Sep 17 00:00:00 2001 From: YSC <84330484+ysc09@users.noreply.github.com> Date: Wed, 25 Mar 2026 01:22:45 -0500 Subject: [PATCH 13/13] update run test Updated run test permission --- .github/workflows/run_test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/run_test.yml b/.github/workflows/run_test.yml index 1dedf219..4b289422 100644 --- a/.github/workflows/run_test.yml +++ b/.github/workflows/run_test.yml @@ -2,6 +2,7 @@ name: simple_calculator unit test permissions: actions: write + contents: write on: [push]