Skip to content

Commit

Permalink
Added Kotlin version of the Gilded Rose Kata
Browse files Browse the repository at this point in the history
  • Loading branch information
mcbeelen committed Aug 26, 2016
1 parent cbb9ae1 commit f713ff1
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 0 deletions.
22 changes: 22 additions & 0 deletions Kotlin/Kotlin.iml
Original file line number Diff line number Diff line change
@@ -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>
58 changes: 58 additions & 0 deletions Kotlin/src/com/gildedrose/GildedRose.kt
Original file line number Diff line number Diff line change
@@ -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
}
}
}
}
}

}

19 changes: 19 additions & 0 deletions Kotlin/src/com/gildedrose/GildedRoseTest.kt
Original file line number Diff line number Diff line change
@@ -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)

}


}


3 changes: 3 additions & 0 deletions Kotlin/src/com/gildedrose/Item.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.gildedrose

data class Item(var name: String, var sellIn: Int, var quality: Int)
36 changes: 36 additions & 0 deletions Kotlin/src/com/gildedrose/TexttestFixture.kt
Original file line number Diff line number Diff line change
@@ -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()
}


}

0 comments on commit f713ff1

Please sign in to comment.