Skip to content

Commit

Permalink
BAEL-2376 Inline classes in kotlin (eugenp#5842)
Browse files Browse the repository at this point in the history
* BAEL-2376 Inline classes in kotlin

* BAEL-2376 Move classes
  • Loading branch information
laurentiud authored and diegomoreira001 committed Dec 16, 2018
1 parent de3479c commit d8e34dc
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.baeldung.inline.classes

inline class InlineDoubleWrapper(val doubleValue : Double)
Original file line number Diff line number Diff line change
@@ -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())
}
}
Original file line number Diff line number Diff line change
@@ -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)
}
}

0 comments on commit d8e34dc

Please sign in to comment.