diff --git a/Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt b/Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt index 077867b6..35cf583d 100644 --- a/Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt +++ b/Kotlin/src/main/kotlin/com/gildedrose/GildedRose.kt @@ -1,6 +1,6 @@ package com.gildedrose -class GildedRose(var items: Array) { +class GildedRose(val items: Array) { fun updateQuality() { for (i in items.indices) { diff --git a/Kotlin/src/test/kotlin/com/gildedrose/GildedRoseTest.kt b/Kotlin/src/test/kotlin/com/gildedrose/GildedRoseTest.kt index 24ae793e..334632cd 100644 --- a/Kotlin/src/test/kotlin/com/gildedrose/GildedRoseTest.kt +++ b/Kotlin/src/test/kotlin/com/gildedrose/GildedRoseTest.kt @@ -1,10 +1,23 @@ package com.gildedrose -import org.junit.jupiter.api.Assertions.assertEquals +import org.junit.jupiter.api.Assertions.* import org.junit.jupiter.api.Test internal class GildedRoseTest { + val items = arrayOf( + Item("+5 Dexterity Vest", 10, 20), // + Item("Aged Brie", 2, 0), // + Item("Elixir of the Mongoose", 5, 7), // + Item("Sulfuras, Hand of Ragnaros", 0, 80), // + Item("Sulfuras, Hand of Ragnaros", -1, 80), + Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), + Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), + Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), + // this conjured item does not work properly yet + Item("Conjured Mana Cake", 3, 6) + ) + @Test fun foo() { val items = arrayOf(Item("foo", 0, 0)) @@ -14,6 +27,37 @@ internal class GildedRoseTest { } + @Test + fun allItemsHaveASellInValue() { + items.forEach { + assertNotNull(it.sellIn) + } + + } + + private val gildedRose = GildedRose(items) + + @Test + fun qualityIsNeverNegative() { + (1..100).forEach { + gildedRose.updateQuality() + items.forEach { + assertTrue(it.quality >= 0, "The quality of an item is never negative") + } + } + } + + @Test + fun agedBrieIncreasesInQuality() { + items.first { it.name == "Aged Brie" }.also { agedBrie -> + while (agedBrie.quality < 50) { + val quality = agedBrie.quality + gildedRose.updateQuality() + assertTrue(agedBrie.quality > quality) + } + } + } + }