refactor: use python instead of javascript
This commit is contained in:
@@ -28,21 +28,16 @@ git config user.email "user@workshop.local" | Out-Null
|
||||
|
||||
# Create initial commits on main
|
||||
$app = @"
|
||||
class Calculator {
|
||||
add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
class Calculator:
|
||||
def add(self, a, b):
|
||||
return a + b
|
||||
|
||||
subtract(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Calculator;
|
||||
def subtract(self, a, b):
|
||||
return a - b
|
||||
"@
|
||||
|
||||
Set-Content -Path "calculator.js" -Value $app
|
||||
git add calculator.js
|
||||
Set-Content -Path "calculator.py" -Value $app
|
||||
git add calculator.py
|
||||
git commit -m "Initial calculator implementation" | Out-Null
|
||||
|
||||
$readme = @"
|
||||
@@ -59,54 +54,41 @@ git commit -m "Add README" | Out-Null
|
||||
git checkout -b local-feature | Out-Null
|
||||
|
||||
$appWithMultiply = @"
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Calculator;
|
||||
def multiply(self, a, b):
|
||||
return a * b
|
||||
"@
|
||||
|
||||
Set-Content -Path "calculator.js" -Value $appWithMultiply
|
||||
git add calculator.js
|
||||
Set-Content -Path "calculator.py" -Value $appWithMultiply
|
||||
git add calculator.py
|
||||
git commit -m "Add multiply function" | Out-Null
|
||||
|
||||
# Add a bad commit that should be removed with reset
|
||||
$appWithBadCode = @"
|
||||
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: This is broken and should never have been committed!
|
||||
divide(a, b) {
|
||||
// Forgot to check for division by zero
|
||||
return a / b; // This will return Infinity or NaN for zero!
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Calculator;
|
||||
# BUG: This is broken and should never have been committed!
|
||||
def divide(self, a, b):
|
||||
# Forgot to check for division by zero
|
||||
return a / b # This will raise ZeroDivisionError for zero!
|
||||
"@
|
||||
|
||||
Set-Content -Path "calculator.js" -Value $appWithBadCode
|
||||
git add calculator.js
|
||||
Set-Content -Path "calculator.py" -Value $appWithBadCode
|
||||
git add calculator.py
|
||||
git commit -m "Add broken divide function - DO NOT KEEP" | Out-Null
|
||||
|
||||
# Switch back to main for shared-feature branch
|
||||
@@ -116,87 +98,70 @@ git checkout main | Out-Null
|
||||
git checkout -b shared-feature | Out-Null
|
||||
|
||||
$appWithPower = @"
|
||||
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
|
||||
|
||||
power(a, b) {
|
||||
return Math.pow(a, b);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = Calculator;
|
||||
def power(self, a, b):
|
||||
return a ** b
|
||||
"@
|
||||
|
||||
Set-Content -Path "calculator.js" -Value $appWithPower
|
||||
git add calculator.js
|
||||
Set-Content -Path "calculator.py" -Value $appWithPower
|
||||
git add calculator.py
|
||||
git commit -m "Add power function" | Out-Null
|
||||
|
||||
# Add a bad commit that should be reverted (not reset)
|
||||
$appWithBrokenFeature = @"
|
||||
class Calculator {
|
||||
add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
import math
|
||||
|
||||
subtract(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
class Calculator:
|
||||
def add(self, a, b):
|
||||
return a + b
|
||||
|
||||
power(a, b) {
|
||||
return Math.pow(a, b);
|
||||
}
|
||||
def subtract(self, a, b):
|
||||
return a - b
|
||||
|
||||
// BUG: This breaks the calculator!
|
||||
squareRoot(a) {
|
||||
// This implementation is wrong for negative numbers
|
||||
return Math.sqrt(a); // Returns NaN for negative numbers without warning!
|
||||
}
|
||||
}
|
||||
def power(self, a, b):
|
||||
return a ** b
|
||||
|
||||
module.exports = Calculator;
|
||||
# BUG: This breaks the calculator!
|
||||
def square_root(self, a):
|
||||
# This implementation is wrong for negative numbers
|
||||
return math.sqrt(a) # Raises ValueError for negative numbers without warning!
|
||||
"@
|
||||
|
||||
Set-Content -Path "calculator.js" -Value $appWithBrokenFeature
|
||||
git add calculator.js
|
||||
Set-Content -Path "calculator.py" -Value $appWithBrokenFeature
|
||||
git add calculator.py
|
||||
git commit -m "Add broken feature" | Out-Null
|
||||
|
||||
# Add another good commit after the bad one (to show that revert preserves subsequent commits)
|
||||
$appWithMoreFeatures = @"
|
||||
class Calculator {
|
||||
add(a, b) {
|
||||
return a + b;
|
||||
}
|
||||
import math
|
||||
|
||||
subtract(a, b) {
|
||||
return a - b;
|
||||
}
|
||||
class Calculator:
|
||||
def add(self, a, b):
|
||||
return a + b
|
||||
|
||||
power(a, b) {
|
||||
return Math.pow(a, b);
|
||||
}
|
||||
def subtract(self, a, b):
|
||||
return a - b
|
||||
|
||||
// BUG: This breaks the calculator!
|
||||
squareRoot(a) {
|
||||
// This implementation is wrong for negative numbers
|
||||
return Math.sqrt(a); // Returns NaN for negative numbers without warning!
|
||||
}
|
||||
def power(self, a, b):
|
||||
return a ** b
|
||||
|
||||
modulo(a, b) {
|
||||
return a % b;
|
||||
}
|
||||
}
|
||||
# BUG: This breaks the calculator!
|
||||
def square_root(self, a):
|
||||
# This implementation is wrong for negative numbers
|
||||
return math.sqrt(a) # Raises ValueError for negative numbers without warning!
|
||||
|
||||
module.exports = Calculator;
|
||||
def modulo(self, a, b):
|
||||
return a % b
|
||||
"@
|
||||
|
||||
Set-Content -Path "calculator.js" -Value $appWithMoreFeatures
|
||||
git add calculator.js
|
||||
Set-Content -Path "calculator.py" -Value $appWithMoreFeatures
|
||||
git add calculator.py
|
||||
git commit -m "Add modulo function" | Out-Null
|
||||
|
||||
# Switch to local-feature for the challenge start
|
||||
|
||||
Reference in New Issue
Block a user