Skip to content

Commit 38545b1

Browse files
committed
sip
1 parent 8cbf06b commit 38545b1

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

core-kotlin-modules/core-kotlin-10/src/test/kotlin/com/baeldung/variableshadowing/VariableShadowingUnitTest.kt

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ class VariableShadowingUnitTest{
108108

109109
assertEquals(100, Car().speed)
110110
assertEquals(200, Car().upSpeed())
111+
assertEquals(200, Car().newSpeed())
111112

112113
fun calculateTotalPrice(discount: Int) {
113114
val updatedDiscount = discount + 10 // Using a new variable name to avoid shadowing
@@ -116,24 +117,16 @@ class VariableShadowingUnitTest{
116117
val price = 100 // local variable
117118
val discountRate = 0.1
118119

119-
fun applyDiscount(price: Int): Double {
120-
val discountRate = 0.2
121-
return price * (1 - discountRate)
122-
}
123-
124-
fun applyDiscountFood(price: Int): Double {
125-
val discountRate = 0.4
126-
return price * (1 - discountRate)
127-
}
120+
// fun applyDiscount(price: Int): Double {
121+
// val innerDiscountRate = 0.2
122+
// return price * (1 - discountRate)
123+
// }
128124

129-
fun applyDiscountDrink(price: Int): Double {
130-
val discountRate = 0.5
131-
return price * (1 - discountRate)
125+
fun applyDiscount(price: Int): Double {
126+
return price * (1 - discountRate) // Use the outer discountRate directly
132127
}
133128

134-
assertEquals(80.0, applyDiscount(price))
135-
assertEquals(50.0, applyDiscountDrink(price))
136-
assertEquals(60.0, applyDiscountFood(price))
129+
assertEquals(90.0, applyDiscount(price))
137130
}
138131

139132
calculateTotalPrice(20)

0 commit comments

Comments
 (0)