BAEL-2376 Inline classes in kotlin (#5842)
* BAEL-2376 Inline classes in kotlin * BAEL-2376 Move classes
This commit is contained in:
parent
de3479ca78
commit
d8e34dc9f2
|
@ -0,0 +1,14 @@
|
|||
package com.baeldung.inline.classes
|
||||
|
||||
interface Drawable {
|
||||
fun draw()
|
||||
}
|
||||
|
||||
inline class CircleRadius(private val circleRadius : Double) : Drawable {
|
||||
val diameterOfCircle get() = 2 * circleRadius
|
||||
fun areaOfCircle() = 3.14 * circleRadius * circleRadius
|
||||
|
||||
override fun draw() {
|
||||
println("Draw my circle")
|
||||
}
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
package com.baeldung.inline.classes
|
||||
|
||||
inline class InlineDoubleWrapper(val doubleValue : Double)
|
|
@ -0,0 +1,19 @@
|
|||
package com.baeldung.inline.classes
|
||||
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class CircleRadiusTest {
|
||||
|
||||
@Test
|
||||
fun givenRadius_ThenDiameterIsCorrectlyCalculated() {
|
||||
val radius = CircleRadius(5.0)
|
||||
assertEquals(10.0, radius.diameterOfCircle)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun givenRadius_ThenAreaIsCorrectlyCalculated() {
|
||||
val radius = CircleRadius(5.0)
|
||||
assertEquals(78.5, radius.areaOfCircle())
|
||||
}
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
package com.baeldung.inline.classes
|
||||
|
||||
import org.junit.Test
|
||||
import kotlin.test.assertEquals
|
||||
|
||||
class InlineDoubleWrapperTest {
|
||||
|
||||
@Test
|
||||
fun whenInclineClassIsUsed_ThenPropertyIsReadCorrectly() {
|
||||
val piDoubleValue = InlineDoubleWrapper(3.14)
|
||||
assertEquals(3.14, piDoubleValue.doubleValue)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue