You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: core-kotlin-modules/core-kotlin-10/src/test/kotlin/com/baeldung/variableshadowing/VariableShadowingUnitTest.kt
+8-15Lines changed: 8 additions & 15 deletions
Original file line number
Diff line number
Diff line change
@@ -108,6 +108,7 @@ class VariableShadowingUnitTest{
108
108
109
109
assertEquals(100, Car().speed)
110
110
assertEquals(200, Car().upSpeed())
111
+
assertEquals(200, Car().newSpeed())
111
112
112
113
funcalculateTotalPrice(discount:Int) {
113
114
val updatedDiscount = discount +10// Using a new variable name to avoid shadowing
@@ -116,24 +117,16 @@ class VariableShadowingUnitTest{
116
117
val price =100// local variable
117
118
val discountRate =0.1
118
119
119
-
funapplyDiscount(price:Int): Double {
120
-
val discountRate =0.2
121
-
return price * (1- discountRate)
122
-
}
123
-
124
-
funapplyDiscountFood(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
+
// }
128
124
129
-
funapplyDiscountDrink(price:Int): Double {
130
-
val discountRate =0.5
131
-
return price * (1- discountRate)
125
+
funapplyDiscount(price:Int): Double {
126
+
return price * (1- discountRate) // Use the outer discountRate directly
0 commit comments