diff --git a/Kotlin/.gitignore b/Kotlin/.gitignore new file mode 100644 index 00000000..d2d5712a --- /dev/null +++ b/Kotlin/.gitignore @@ -0,0 +1,3 @@ +.idea/ +out/ +*.class diff --git a/Kotlin/Kotlin.iml b/Kotlin/Kotlin.iml new file mode 100644 index 00000000..6ee397d4 --- /dev/null +++ b/Kotlin/Kotlin.iml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Kotlin/src/com/gildedrose/GildedRose.kt b/Kotlin/src/com/gildedrose/GildedRose.kt new file mode 100644 index 00000000..a78cd532 --- /dev/null +++ b/Kotlin/src/com/gildedrose/GildedRose.kt @@ -0,0 +1,58 @@ +package com.gildedrose + +class GildedRose(var items: Array) { + + fun updateQuality() { + for (i in items.indices) { + if (!items[i].name.equals("Aged Brie") && !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (items[i].quality > 0) { + if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { + items[i].quality = items[i].quality - 1 + } + } + } else { + if (items[i].quality < 50) { + items[i].quality = items[i].quality + 1 + + if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (items[i].sellIn < 11) { + if (items[i].quality < 50) { + items[i].quality = items[i].quality + 1 + } + } + + if (items[i].sellIn < 6) { + if (items[i].quality < 50) { + items[i].quality = items[i].quality + 1 + } + } + } + } + } + + if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { + items[i].sellIn = items[i].sellIn - 1 + } + + if (items[i].sellIn < 0) { + if (!items[i].name.equals("Aged Brie")) { + if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) { + if (items[i].quality > 0) { + if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) { + items[i].quality = items[i].quality - 1 + } + } + } else { + items[i].quality = items[i].quality - items[i].quality + } + } else { + if (items[i].quality < 50) { + items[i].quality = items[i].quality + 1 + } + } + } + } + } + +} + diff --git a/Kotlin/src/com/gildedrose/GildedRoseTest.kt b/Kotlin/src/com/gildedrose/GildedRoseTest.kt new file mode 100644 index 00000000..5515dcdc --- /dev/null +++ b/Kotlin/src/com/gildedrose/GildedRoseTest.kt @@ -0,0 +1,19 @@ +package com.gildedrose + +import org.junit.Assert.* +import org.junit.Test + +class GildedRoseTest { + + @Test fun foo() { + val items = arrayOf(Item("foo", 0, 0)) + val app = GildedRose(items) + app.updateQuality() + assertEquals("fixme", app.items[0].name) + + } + + +} + + diff --git a/Kotlin/src/com/gildedrose/Item.kt b/Kotlin/src/com/gildedrose/Item.kt new file mode 100644 index 00000000..29d714ba --- /dev/null +++ b/Kotlin/src/com/gildedrose/Item.kt @@ -0,0 +1,3 @@ +package com.gildedrose + +data class Item(var name: String, var sellIn: Int, var quality: Int) \ No newline at end of file diff --git a/Kotlin/src/com/gildedrose/TexttestFixture.kt b/Kotlin/src/com/gildedrose/TexttestFixture.kt new file mode 100644 index 00000000..7eeac81e --- /dev/null +++ b/Kotlin/src/com/gildedrose/TexttestFixture.kt @@ -0,0 +1,36 @@ +package com.gildedrose + +fun main(args: Array) { + + println("OMGHAI!") + + 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)) + + val app = GildedRose(items) + + var days = 2 + if (args.size > 0) { + days = Integer.parseInt(args[0]) + 1 + } + + for (i in 0..days - 1) { + println("-------- day $i --------") + println("name, sellIn, quality") + for (item in items) { + println(item) + } + println() + app.updateQuality() + } + + +}