Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 85 additions & 0 deletions LEARNINGS-tngwafor.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# LEARNINGS-tngwafor

## CP1
### Commands
```bash
git checkout starter/role-D
git checkout -b feature/tngwafor
git push -u origin feature/tngwafor
pytest tests/
git add tests/test_calculator.py
git commit -m "fix"
git add .gitignore
git commit -m "update"
git push origin feature/tngwafor

Reflection :
I learned how to use the staging area to separate unrelated changes into different commits. This matters because clean commits make code review and debugging much easier.

Checkpoint 2
git log --oneline
git revert 6ca467b
pytest tests/
git push origin feature/tngwafor

Reflection :
I learned how to undo a bad commit with git revert without deleting history. This matters because it preserves a clear project history while safely reversing unwanted changes.

Checkpoint 3
git checkout main
git add src/validator.py
git commit -m "Add is_positive helper function"
git log --oneline -1
git reset --hard HEAD~1
git checkout feature/tngwafor
git cherry-pick 8611771
git add src/validator.py
git cherry-pick --continue
pytest tests/
git push origin feature/tngwafor

Reflection :
I learned how to move work from the wrong branch to the correct one using git cherry-pick. This matters because mistakes happen, and knowing how to recover cleanly helps keep branches organized.


Checkpoint 4 :
git checkout -b experiment/tngwafor
git add src/validator.py
git commit -m "Add experimental comment"
git checkout feature/tngwafor
git branch -D experiment/tngwafor
git reflog
git checkout -b recovered/tngwafor <lost-commit-hash>
git checkout feature/tngwafor
git merge recovered/tngwafor
pytest tests/
git push origin feature/tngwafor

Reflection :
I learned that git reflog can recover commits even after a branch is deleted. This matters because it provides a safety net when work seems lost.

Checkpoint 5 :
git fetch upstream
git checkout main
git reset --hard upstream/main
git checkout feature/tngwafor
git rebase main
pytest tests/
git push --force-with-lease origin feature/tngwafor


Reflection :
I learned how to sync my branch with the latest upstream changes using fetch, reset, and rebase. This matters because it keeps my work up to date and reduces messy merge history.


Checkpoint 6 :
git log main..HEAD --oneline
git rebase -i main
pytest tests/
git push --force-with-lease origin feature/tngwafor


Reflection :
I learned how to clean up commit history with interactive rebase by rewording and organizing commits. This matters because a clean history makes the development process easier to understand and review.


2 changes: 2 additions & 0 deletions src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
_pychache_/
*.pyc
11 changes: 11 additions & 0 deletions src/calculator.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,14 @@ def divide(a, b):
if b == 0:
raise ValueError("Cannot divide by zero")
return a / b

def factorial(n):
"""Calculate factorial of n."""
if n < 0:
raise ValueError("Cannot calculate factorial of negative number")
if n == 0 or n == 1:
return 1
result = 1
for i in range(2, n + 1):
result *= i
return result
14 changes: 14 additions & 0 deletions src/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,17 @@ def validate_operation(op):
"""Validate that operation is supported."""
valid_ops = ['+', '-', '*', '/']
return op in valid_ops

def validate_integer(n):
"""Validate that a number is an integer."""
try:
num = float(n)
return num == int(num)
except (ValueError, TypeError):
return False

def is_positive(n):
"""Check if a number is positive."""
return n > 0

#Change for checkpoint 4
17 changes: 16 additions & 1 deletion tests/test_calculator.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Tests for calculator operations."""
import pytest
from src.calculator import add, subtract, multiply, divide
from src.calculator import add, subtract, multiply, divide, factorial
from src.validator import validate_integer

def test_add():
assert add(2, 3) == 5
Expand All @@ -21,3 +22,17 @@ def test_divide():
def test_divide_by_zero():
with pytest.raises(ValueError):
divide(5, 0)

def test_factorial():
assert factorial(0) == 1
assert factorial(5) == 120
assert factorial(3) == 6

def test_factorial_negative():
with pytest.raises(ValueError):
factorial(-1)

def test_validate_integer():
assert validate_integer(5) == True
assert validate_integer(5.0) == True
assert validate_integer(5.5) == False