diff --git a/core-kotlin/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt b/core-kotlin/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt new file mode 100644 index 0000000000..5b46b9570f --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/inline/classes/CircleRadius.kt @@ -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") + } +} \ No newline at end of file diff --git a/core-kotlin/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt b/core-kotlin/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt new file mode 100644 index 0000000000..430fa509da --- /dev/null +++ b/core-kotlin/src/main/kotlin/com/baeldung/inline/classes/InlineDoubleWrapper.kt @@ -0,0 +1,3 @@ +package com.baeldung.inline.classes + +inline class InlineDoubleWrapper(val doubleValue : Double) \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt new file mode 100644 index 0000000000..8de378b6dd --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/inline/classes/CircleRadiusTest.kt @@ -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()) + } +} \ No newline at end of file diff --git a/core-kotlin/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt b/core-kotlin/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt new file mode 100644 index 0000000000..349c90d6f4 --- /dev/null +++ b/core-kotlin/src/test/kotlin/com/baeldung/inline/classes/InlineDoubleWrapperTest.kt @@ -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) + } +} \ No newline at end of file