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
|
||||
|
||||
Reference in New Issue
Block a user