Skip to content

Commit 516415d

Browse files
committed
suppressed unused
1 parent 4e7ba90 commit 516415d

File tree

1 file changed

+3
-92
lines changed

1 file changed

+3
-92
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
@file:Suppress("UNUSED_PARAMETER", "UNUSED_VARIABLE", "UNUSED_ANONYMOUS_PARAMETER")
2+
13
package com.baeldung.variableshadowing
24

35
import org.junit.jupiter.api.Assertions.assertEquals
@@ -70,7 +72,7 @@ class VariableShadowingUnitTest{
7072

7173
// in lambda
7274
var sum = 0
73-
var values = listOf(1, 2, 3, 4, 5)
75+
val values = listOf(1, 2, 3, 4, 5)
7476

7577
values.forEach { value ->
7678
val value = 0
@@ -80,95 +82,4 @@ class VariableShadowingUnitTest{
8082
assertEquals(0, sum)
8183
}
8284

83-
// @Test
84-
// fun `local variable or nested function shadowing`() {
85-
//
86-
// fun calculateTotalPrice() {
87-
// val price = 100 // local variable
88-
// val discountRate = 0.1
89-
//
90-
// fun applyDiscount(price: Int): Double { // Nested function with parameter named 'price'
91-
// val discountRate = 0.2 // Inner variable shadows the outer variable
92-
// return price * (1 - discountRate) // 'price' here refers to the parameter, not the outer variable
93-
// }
94-
//
95-
// assertEquals(80.0, applyDiscount(price))
96-
// }
97-
//
98-
// calculateTotalPrice()
99-
// }
100-
101-
// @Test
102-
// fun `loop variable shadowing`() {
103-
// val numbers = listOf(1, 2, 3, 4, 5)
104-
// for (number in numbers) {
105-
// val doubledNumber = number * 2
106-
// val number = number * 2 // Shadowing the loop variable 'number'
107-
//
108-
// assertEquals(doubledNumber, number)
109-
// }
110-
// }
111-
112-
113-
@Test
114-
fun `parameter shadowing`() {
115-
fun calculateTotalPrice(discount: Int) {
116-
assertEquals(300, discount)
117-
118-
val discount = 10 // Shadowing the parameter 'discount'
119-
assertEquals(10, discount)
120-
121-
val price = 100
122-
val totalPrice = price - discount
123-
assertEquals(90, totalPrice)
124-
}
125-
126-
calculateTotalPrice(300)
127-
}
128-
129-
// @Test
130-
// fun `nested function variable shadowing`(){
131-
// fun calculateDiscount(originalPrice: Double) {
132-
// val discountRate = 0.1 // Outer variable
133-
//
134-
// fun applyDiscount(price: Double): Double { // Nested function with parameter 'price'
135-
// val discountRate = 0.2 // Inner variable shadows the outer variable
136-
// return price * (1 - discountRate)
137-
// }
138-
//
139-
// val discountedPrice = applyDiscount(originalPrice)
140-
// println("Discounted price: $$discountedPrice")
141-
// }
142-
//
143-
// calculateDiscount(200.0)
144-
// }
145-
146-
// @Test
147-
// fun `variable shadowing in lambda`(){
148-
// var sum = 0
149-
// var values = listOf(1, 2, 3, 4, 5)
150-
//
151-
// values.forEach { value ->
152-
// val value = 0
153-
// sum += value
154-
// }
155-
//
156-
// assertEquals(0, sum)
157-
// }
158-
159-
// @Test
160-
// fun `shadowing in extension`(){
161-
// val numbers = listOf(1, 2, 3, 4, 5)
162-
//
163-
// assertEquals(15, numbers.sum())
164-
//
165-
// fun List<Int>.sum(): Int { // Shadowing occur in here
166-
// var sum = 0 // shadowing built-in function sum()
167-
// this.forEach { sum += it * 2 }
168-
// return sum
169-
// }
170-
//
171-
// assertEquals(30, numbers.sum())
172-
// }
173-
17485
}

0 commit comments

Comments
 (0)