refactor: use python instead of javascript
This commit is contained in:
@@ -31,30 +31,23 @@ git config user.email "user@workshop.local" | Out-Null
|
||||
|
||||
# Create initial calculator with a bug
|
||||
$calculator = @"
|
||||
class Calculator {
|
||||
add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
class Calculator:
|
||||
def add(self, a, b):
|
||||
return a + b
|
||||
|
||||
subtract(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
def subtract(self, a, b):
|
||||
return a - b
|
||||
|
||||
multiply(a, b) {
|
||||
return a * b;
|
||||
}
|
||||
def multiply(self, a, b):
|
||||
return a * b
|
||||
|
||||
// BUG: No division by zero check!
|
||||
divide(a, b) {
|
||||
return a / b;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Calculator;
|
||||
# BUG: No division by zero check!
|
||||
def divide(self, a, b):
|
||||
return a / b
|
||||
"@
|
||||
|
||||
Set-Content -Path "calculator.js" -Value $calculator
|
||||
git add calculator.js
|
||||
Set-Content -Path "calculator.py" -Value $calculator
|
||||
git add calculator.py
|
||||
git commit -m "Initial calculator implementation" | Out-Null
|
||||
|
||||
$readme = @"
|
||||
@@ -78,38 +71,30 @@ git checkout -b feature-advanced-math | Out-Null
|
||||
|
||||
# Add work in progress on feature branch
|
||||
$calculatorWithFeature = @"
|
||||
class Calculator {
|
||||
add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
class Calculator:
|
||||
def add(self, a, b):
|
||||
return a + b
|
||||
|
||||
subtract(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
def subtract(self, a, b):
|
||||
return a - b
|
||||
|
||||
multiply(a, b) {
|
||||
return a * b;
|
||||
}
|
||||
def multiply(self, a, b):
|
||||
return a * b
|
||||
|
||||
// BUG: No division by zero check!
|
||||
divide(a, b) {
|
||||
return a / b;
|
||||
}
|
||||
# BUG: No division by zero check!
|
||||
def divide(self, a, b):
|
||||
return a / b
|
||||
|
||||
// New feature: power function (work in progress)
|
||||
power(a, b) {
|
||||
return Math.pow(a, b);
|
||||
}
|
||||
# New feature: power function (work in progress)
|
||||
def power(self, a, b):
|
||||
return a ** b
|
||||
|
||||
// TODO: Add square root function
|
||||
// TODO: Add logarithm function
|
||||
}
|
||||
|
||||
module.exports = Calculator;
|
||||
# TODO: Add square root function
|
||||
# TODO: Add logarithm function
|
||||
"@
|
||||
|
||||
Set-Content -Path "calculator.js" -Value $calculatorWithFeature
|
||||
git add calculator.js
|
||||
Set-Content -Path "calculator.py" -Value $calculatorWithFeature
|
||||
git add calculator.py
|
||||
git commit -m "Add power function (WIP: more math functions coming)" | Out-Null
|
||||
|
||||
# Return to challenge directory
|
||||
@@ -128,11 +113,11 @@ Write-Host "`nYour task:" -ForegroundColor Yellow
|
||||
Write-Host "1. Navigate to main-repo: cd challenge/main-repo" -ForegroundColor White
|
||||
Write-Host "2. Create a worktree: git worktree add ../bugfix-worktree -b bugfix" -ForegroundColor White
|
||||
Write-Host "3. Go to worktree: cd ../bugfix-worktree" -ForegroundColor White
|
||||
Write-Host "4. Fix the bug in calculator.js:" -ForegroundColor White
|
||||
Write-Host "4. Fix the bug in calculator.py:" -ForegroundColor White
|
||||
Write-Host " Add a check: if (b === 0) throw new Error('Division by zero');" -ForegroundColor White
|
||||
Write-Host "5. Commit the fix: git add . && git commit -m 'Fix divide by zero bug'" -ForegroundColor White
|
||||
Write-Host "6. Return to main-repo: cd ../main-repo" -ForegroundColor White
|
||||
Write-Host "7. Complete your feature: Add square root method to calculator.js" -ForegroundColor White
|
||||
Write-Host "7. Complete your feature: Add square root method to calculator.py" -ForegroundColor White
|
||||
Write-Host "8. Commit: git add . && git commit -m 'Add square root function'" -ForegroundColor White
|
||||
Write-Host "9. Clean up worktree: git worktree remove ../bugfix-worktree" -ForegroundColor White
|
||||
Write-Host "`nRun '../verify.ps1' from the challenge directory to check your solution.`n" -ForegroundColor Cyan
|
||||
|
||||
@@ -55,13 +55,13 @@ Write-Host "[PASS] Bugfix branch exists!" -ForegroundColor Green
|
||||
# Check bugfix branch for the fix
|
||||
git checkout bugfix 2>$null | Out-Null
|
||||
|
||||
if (-not (Test-Path "calculator.js")) {
|
||||
Write-Host "[FAIL] calculator.js not found on bugfix branch." -ForegroundColor Red
|
||||
if (-not (Test-Path "calculator.py")) {
|
||||
Write-Host "[FAIL] calculator.py not found on bugfix branch." -ForegroundColor Red
|
||||
Set-Location ../..
|
||||
exit 1
|
||||
}
|
||||
|
||||
$bugfixCalc = Get-Content "calculator.js" -Raw
|
||||
$bugfixCalc = Get-Content "calculator.py" -Raw
|
||||
|
||||
# Check if division by zero check was added
|
||||
if ($bugfixCalc -notmatch "b === 0|b == 0|division by zero|divide by zero") {
|
||||
@@ -85,12 +85,12 @@ Write-Host "[PASS] Bug fixed on bugfix branch!" -ForegroundColor Green
|
||||
# Check feature branch for continued work
|
||||
git checkout feature-advanced-math 2>$null | Out-Null
|
||||
|
||||
$featureCalc = Get-Content "calculator.js" -Raw
|
||||
$featureCalc = Get-Content "calculator.py" -Raw
|
||||
|
||||
# Check if square root function was added
|
||||
if ($featureCalc -notmatch "sqrt|squareRoot") {
|
||||
Write-Host "[FAIL] Square root function not found on feature branch." -ForegroundColor Red
|
||||
Write-Host "Hint: Add the square root method to calculator.js on feature-advanced-math branch" -ForegroundColor Yellow
|
||||
Write-Host "Hint: Add the square root method to calculator.py on feature-advanced-math branch" -ForegroundColor Yellow
|
||||
Set-Location ../..
|
||||
exit 1
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user