From 59769653839ded2b9924a1eb3c3b468d81c1f875 Mon Sep 17 00:00:00 2001 From: Mohammad Durrani Date: Sat, 7 Feb 2026 16:30:04 -0500 Subject: [PATCH 01/10] Add power operation support --- src/calculator.py | 4 ++++ tests/test_calculator.py | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/src/calculator.py b/src/calculator.py index e828684..e94d423 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -17,3 +17,7 @@ def divide(a, b): if b == 0: raise ValueError("Cannot divide by zero") return a / b + +def power(a, b): + """Raise a to the power of b.""" + return a ** b diff --git a/tests/test_calculator.py b/tests/test_calculator.py index ffc0154..0e5160d 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -21,3 +21,8 @@ def test_divide(): def test_divide_by_zero(): with pytest.raises(ValueError): divide(5, 0) + +def test_power(): + assert power(2, 3) == 8 + assert power(5, 2) == 25 + assert power(10, 0) == 0 From b19f2334eadf9de509392fba04e125416fe5d53e Mon Sep 17 00:00:00 2001 From: Mohammad Durrani Date: Sat, 7 Feb 2026 16:30:13 -0500 Subject: [PATCH 02/10] BAD: Add excessive debug logging to calculator module --- src/calculator.py | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/src/calculator.py b/src/calculator.py index e94d423..1ffb5ec 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -2,22 +2,38 @@ def add(a, b): """Add two numbers.""" - return a + b + print(f"[DEBUG] Adding {a} + {b}") + result = a + b + print(f"[DEBUG] Result: {result}") + return result def subtract(a, b): """Subtract b from a.""" - return a - b + print(f"[DEBUG] Subtracting {a} - {b}") + result = a - b + print(f"[DEBUG] Result: {result}") + return result def multiply(a, b): """Multiply two numbers.""" - return a * b + print(f"[DEBUG] Multiplying {a} * {b}") + result = a * b + print(f"[DEBUG] Result: {result}") + return result def divide(a, b): """Divide a by b.""" + print(f"[DEBUG] Dividing {a} / {b}") if b == 0: + print(f"[DEBUG] Error: Division by zero!") raise ValueError("Cannot divide by zero") - return a / b + result = a / b + print(f"[DEBUG] Result: {result}") + return result def power(a, b): """Raise a to the power of b.""" - return a ** b + print(f"[DEBUG] Power {a} ** {b}") + result = a ** b + print(f"[DEBUG] Result: {result}") + return result From d4a52e208e319fdfc6a674bc28caea2e73e1de6a Mon Sep 17 00:00:00 2001 From: Mohammad Durrani Date: Sat, 7 Feb 2026 16:30:21 -0500 Subject: [PATCH 03/10] FEATURE: Add positive number validation --- src/validator.py | 8 ++++++++ tests/test_calculator.py | 6 ++++++ 2 files changed, 14 insertions(+) diff --git a/src/validator.py b/src/validator.py index 7a70d84..c3091e4 100644 --- a/src/validator.py +++ b/src/validator.py @@ -12,3 +12,11 @@ def validate_operation(op): """Validate that operation is supported.""" valid_ops = ['+', '-', '*', '/'] return op in valid_ops + +def validate_positive(n): + """Validate that a number is positive.""" + try: + num = float(n) + return num > 0 + except (ValueError, TypeError): + return False diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 0e5160d..681e101 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -1,6 +1,7 @@ """Tests for calculator operations.""" import pytest from src.calculator import add, subtract, multiply, divide +from src.validator import validate_positive def test_add(): assert add(2, 3) == 5 @@ -26,3 +27,8 @@ def test_power(): assert power(2, 3) == 8 assert power(5, 2) == 25 assert power(10, 0) == 0 + +def test_validate_positive(): + assert validate_positive(5) == True + assert validate_positive(-5) == False + assert validate_positive(0) == False From e444f125542500560600656980203061f86e11c3 Mon Sep 17 00:00:00 2001 From: Prajwal Date: Fri, 27 Mar 2026 21:19:03 -0400 Subject: [PATCH 04/10] Fix test_power: add import and correct expected value --- tests/test_calculator.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 681e101..343d107 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -1,6 +1,6 @@ """Tests for calculator operations.""" import pytest -from src.calculator import add, subtract, multiply, divide +from src.calculator import add, subtract, multiply, divide, power from src.validator import validate_positive def test_add(): @@ -26,7 +26,7 @@ def test_divide_by_zero(): def test_power(): assert power(2, 3) == 8 assert power(5, 2) == 25 - assert power(10, 0) == 0 + assert power(10, 0) == 1 def test_validate_positive(): assert validate_positive(5) == True From e07a3938b6fe146ff9a8708f94ff97191439f524 Mon Sep 17 00:00:00 2001 From: Prajwal Date: Fri, 27 Mar 2026 21:19:03 -0400 Subject: [PATCH 05/10] Add module-level docstring to validator.py --- src/validator.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/validator.py b/src/validator.py index c3091e4..f20a972 100644 --- a/src/validator.py +++ b/src/validator.py @@ -1,4 +1,8 @@ -"""Input validation for calculator.""" +"""Input validation for calculator. + +This module provides functions to validate user inputs before performing +calculator operations, ensuring values are numeric and operations are supported. +""" def validate_number(value): """Validate that value can be converted to a number.""" From 947787e46709a7fdfe666d08ab00739d273c525f Mon Sep 17 00:00:00 2001 From: Prajwal Date: Fri, 27 Mar 2026 21:19:03 -0400 Subject: [PATCH 06/10] Revert "BAD: Add excessive debug logging to calculator module" This reverts commit b19f2334eadf9de509392fba04e125416fe5d53e. --- src/calculator.py | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/src/calculator.py b/src/calculator.py index 1ffb5ec..e94d423 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -2,38 +2,22 @@ def add(a, b): """Add two numbers.""" - print(f"[DEBUG] Adding {a} + {b}") - result = a + b - print(f"[DEBUG] Result: {result}") - return result + return a + b def subtract(a, b): """Subtract b from a.""" - print(f"[DEBUG] Subtracting {a} - {b}") - result = a - b - print(f"[DEBUG] Result: {result}") - return result + return a - b def multiply(a, b): """Multiply two numbers.""" - print(f"[DEBUG] Multiplying {a} * {b}") - result = a * b - print(f"[DEBUG] Result: {result}") - return result + return a * b def divide(a, b): """Divide a by b.""" - print(f"[DEBUG] Dividing {a} / {b}") if b == 0: - print(f"[DEBUG] Error: Division by zero!") raise ValueError("Cannot divide by zero") - result = a / b - print(f"[DEBUG] Result: {result}") - return result + return a / b def power(a, b): """Raise a to the power of b.""" - print(f"[DEBUG] Power {a} ** {b}") - result = a ** b - print(f"[DEBUG] Result: {result}") - return result + return a ** b From 2e379d0a3e0c4b8ca5cd0a4521ed41c4f3f1fd7f Mon Sep 17 00:00:00 2001 From: Prajwal Date: Fri, 27 Mar 2026 21:19:03 -0400 Subject: [PATCH 07/10] Add is_positive helper function --- src/validator.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/validator.py b/src/validator.py index f20a972..1766b90 100644 --- a/src/validator.py +++ b/src/validator.py @@ -24,3 +24,7 @@ def validate_positive(n): return num > 0 except (ValueError, TypeError): return False + +def is_positive(n): + """Check if a number is positive.""" + return n > 0 From e0e7300c2e71b87ec5704d3f8af1c8916bd6f7d7 Mon Sep 17 00:00:00 2001 From: Prajwal Date: Fri, 27 Mar 2026 21:19:03 -0400 Subject: [PATCH 08/10] Experiment: add placeholder comment for future features --- src/calculator.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/calculator.py b/src/calculator.py index e94d423..672379a 100644 --- a/src/calculator.py +++ b/src/calculator.py @@ -21,3 +21,4 @@ def divide(a, b): def power(a, b): """Raise a to the power of b.""" return a ** b +# Experimental feature placeholder From 71cce51a866422aca65630b01f9f03f8509e8586 Mon Sep 17 00:00:00 2001 From: Prajwal Date: Fri, 27 Mar 2026 21:19:03 -0400 Subject: [PATCH 09/10] Add LEARNINGS-120080258.md --- LEARNINGS-120080258.md | 86 ++++++++++++++++++++++++++++++++++++++++++ src/validator.py | 6 +-- 2 files changed, 89 insertions(+), 3 deletions(-) create mode 100644 LEARNINGS-120080258.md diff --git a/LEARNINGS-120080258.md b/LEARNINGS-120080258.md new file mode 100644 index 0000000..2c253b4 --- /dev/null +++ b/LEARNINGS-120080258.md @@ -0,0 +1,86 @@ +# LEARNINGS-120080258 + +## cp1: staging is not committing + +**Commands:** +``` +git checkout -b starter/role-B origin/starter/role-B +git checkout -b feature/120080258 +git add tests/test_calculator.py +git commit -m "fix" +git add src/validator.py +git commit -m "update" +``` + +**Reflection:** The staging area lets you pick which changes go into each commit and when multiple files are modified. This keeps history clean and makes each commit tell anyone what went on. + + +## cp2: undo without erasing history + +**Commands:** +``` +git log --oneline +git revert b19f233 --no-edit +``` + +**Reflection:** git revert undoes a commit by adding a new one and history stays intact. This is safe for shared branches since it doesn't rewrite anything at all. + +## cp3: moving a commit to the right branch + +**Commands:** +``` +git checkout main +git add src/validator.py +git commit -m "Add is_positive helper function" +git reset --hard HEAD~1 +git checkout feature/120080258 +git cherry-pick 38d4a17 +git add src/validator.py +git cherry-pick --continue --no-edit +``` + +**Reflection:** git cherry-pick lets you replay a specific commit onto any branch. Conflicts just mean both branches touched the same file — resolve them by keeping both sides. + +## cp4: recovering lost work with reflog + +**Commands:** +``` +git checkout -b experiment/120080258 +git add src/calculator.py +git commit -m "Experiment: add placeholder comment for future features" +git checkout feature/120080258 +git branch -D experiment/120080258 +git reflog +git checkout -b recovered/120080258 ea413e6 +git merge recovered/120080258 --no-edit +``` + +**Reflection:** Deleting a branch doesn't delete its commits all git reflog does is tracks every HEAD movement and lets you recover orphaned lost work. + + +## cp5: syncing with upstream + +**Commands:** +``` +git remote add upstream +git fetch upstream +git checkout main +git merge upstream/main +git checkout feature/120080258 +git rebase main +git push --force-with-lease origin feature/120080258 +``` + +**Reflection:** Having a separate upstream remote lets you pull changes from the source project into your fork. Rebasing keeps history linear and makes PRs easier to review. + +## cp6: interactive rebase to clean up history + +**Commands:** +``` +git log main..HEAD --oneline +git rebase -i HEAD~8 +# reworded "fix" and "update" to descriptive messages +git push --force-with-lease origin feature/120080258 +``` + +**Reflection:** Interactive rebase lets you clean up commits before code review — reorder, squash, or reword them. Using --force-with-lease instead of --force prevents overwriting someone else's pushes. diff --git a/src/validator.py b/src/validator.py index 1766b90..04d8a5e 100644 --- a/src/validator.py +++ b/src/validator.py @@ -1,7 +1,7 @@ """Input validation for calculator. -This module provides functions to validate user inputs before performing -calculator operations, ensuring values are numeric and operations are supported. +handles validation of numbers and operations before they are used +in any calculator function. """ def validate_number(value): @@ -26,5 +26,5 @@ def validate_positive(n): return False def is_positive(n): - """Check if a number is positive.""" + """check if a number is positive.""" return n > 0 From 379a3fa856d3cdacae6cf9ad51a5f68e30819cd0 Mon Sep 17 00:00:00 2001 From: Prajwal Date: Fri, 27 Mar 2026 23:15:45 -0400 Subject: [PATCH 10/10] Add more edge case tests for test_power --- tests/test_calculator.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/test_calculator.py b/tests/test_calculator.py index 343d107..a52231d 100644 --- a/tests/test_calculator.py +++ b/tests/test_calculator.py @@ -27,6 +27,9 @@ def test_power(): assert power(2, 3) == 8 assert power(5, 2) == 25 assert power(10, 0) == 1 + assert power(2, -1) == 0.5 + assert power(0, 5) == 0 + assert power(1, 100) == 1 def test_validate_positive(): assert validate_positive(5) == True