Added Kotlin version of the Gilded Rose Kata

This commit is contained in:
Marco Beelen (Ximedes) 2016-08-26 10:55:09 +02:00
parent cbb9ae16c4
commit f713ff1019
5 changed files with 138 additions and 0 deletions

22
Kotlin/Kotlin.iml Normal file
View File

@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="KotlinJavaRuntime" level="project" />
<orderEntry type="module-library">
<library name="JUnit4">
<CLASSES>
<root url="jar://$APPLICATION_HOME_DIR$/lib/junit-4.12.jar!/" />
<root url="jar://$APPLICATION_HOME_DIR$/lib/hamcrest-core-1.3.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</orderEntry>
</component>
</module>

View File

@ -0,0 +1,58 @@
package com.gildedrose
class GildedRose(var items: Array<Item>) {
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
}
}
}
}
}
}

View File

@ -0,0 +1,19 @@
package com.gildedrose
import org.junit.Assert.*
import org.junit.Test
class GildedRoseTest {
@Test fun foo() {
val items = arrayOf<Item>(Item("foo", 0, 0))
val app = GildedRose(items)
app.updateQuality()
assertEquals("fixme", app.items[0].name)
}
}

View File

@ -0,0 +1,3 @@
package com.gildedrose
data class Item(var name: String, var sellIn: Int, var quality: Int)

View File

@ -0,0 +1,36 @@
package com.gildedrose
fun main(args: Array<String>) {
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()
}
}