diff --git a/Kotlin/README.md b/Kotlin/README.md index c97a1db1..01b53561 100644 --- a/Kotlin/README.md +++ b/Kotlin/README.md @@ -32,3 +32,14 @@ There are instructions in the [TextTest Readme](../texttests/README.md) for sett 2. Break complex statements, make code longer and simpler 3. understand algorithm and propose better solution + +### Execution +TexttestFixtures indeed do not cover all paths, based on jacoco coverage: + ![img.png](img.png) + +There are two ways to advance: +1. manually craft extra test cases +2. auto generate a bunch of test cases + +I prefer to go with (2) because it seems to me to be more resilient way. I need to check if execution +time is not bloated. Also minimize number of test cases. diff --git a/Kotlin/build.gradle.kts b/Kotlin/build.gradle.kts index 4d392304..277a6197 100644 --- a/Kotlin/build.gradle.kts +++ b/Kotlin/build.gradle.kts @@ -3,6 +3,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile plugins { kotlin("jvm") version "1.9.10" application + jacoco } group = "com.gildedrose" @@ -22,6 +23,11 @@ tasks.test { testLogging { events("passed", "skipped", "failed") } + finalizedBy(tasks.jacocoTestReport) +} + +tasks.jacocoTestReport { + dependsOn(tasks.test) } // config JVM target to 1.8 for kotlin compilation tasks diff --git a/Kotlin/img.png b/Kotlin/img.png new file mode 100644 index 00000000..0521f577 Binary files /dev/null and b/Kotlin/img.png differ diff --git a/Kotlin/src/test/kotlin/com/gildedrose/GildedRoseTest.kt b/Kotlin/src/test/kotlin/com/gildedrose/GildedRoseTest.kt index c5216d8a..52af8f7d 100644 --- a/Kotlin/src/test/kotlin/com/gildedrose/GildedRoseTest.kt +++ b/Kotlin/src/test/kotlin/com/gildedrose/GildedRoseTest.kt @@ -2,6 +2,15 @@ package com.gildedrose import org.junit.jupiter.api.Assertions.assertEquals import org.junit.jupiter.api.Test +import org.junit.jupiter.api.assertAll +import org.junit.jupiter.api.extension.ExtensionContext +import org.junit.jupiter.params.ParameterizedTest +import org.junit.jupiter.params.provider.Arguments +import org.junit.jupiter.params.provider.Arguments.of +import org.junit.jupiter.params.provider.ArgumentsProvider +import org.junit.jupiter.params.provider.ArgumentsSource +import java.util.stream.Stream + internal class GildedRoseTest { @@ -10,10 +19,41 @@ internal class GildedRoseTest { val items = listOf(Item("foo", 0, 0)) val app = GildedRose(items) app.updateQuality() - assertEquals("fixme", app.items[0].name) + assertEquals("foo", app.items[0].name) } + @ParameterizedTest + @ArgumentsSource(GildedRoseArgumentsProvider::class) + fun `should update quality`(item: Item, expectedQuality: Int, expectedSellIn: Int) { + val itemName = item.name + val items = listOf(item) + val app = GildedRose(items) + app.updateQuality() + assertAll( + { assertEquals(itemName, app.items[0].name) }, + { assertEquals(expectedQuality, app.items[0].quality) }, + { assertEquals(expectedSellIn, app.items[0].sellIn) } + ) + } + + class GildedRoseArgumentsProvider : ArgumentsProvider { + override fun provideArguments(context: ExtensionContext): Stream { + return Stream.of( + of(Item("+5 Dexterity Vest", 10, 20), 19, 9), + of(Item("Aged Brie", 2, 0), 1, 1), + of(Item("Elixir of the Mongoose", 5, 7), 6, 4), + of(Item("Sulfuras, Hand of Ragnaros", 0, 80), 80, 0), + of(Item("Sulfuras, Hand of Ragnaros", -1, 80), 80, -1), + of(Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), 21, 14), + of(Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), 50, 9), + of(Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), 50, 4), + // this conjured item does not work properly yet + // of(Item("Conjured Mana Cake", 3, 6), 5, 2), // TODO: enabled and fix after refactor + ) + } + } + }