mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Merge pull request #42 from mcbeelen/Kotlin
Added Kotlin version of the Gilded Rose Kata
This commit is contained in:
commit
378a111775
3
Kotlin/.gitignore
vendored
Normal file
3
Kotlin/.gitignore
vendored
Normal file
@ -0,0 +1,3 @@
|
||||
.idea/
|
||||
out/
|
||||
*.class
|
||||
22
Kotlin/Kotlin.iml
Normal file
22
Kotlin/Kotlin.iml
Normal 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>
|
||||
58
Kotlin/src/com/gildedrose/GildedRose.kt
Normal file
58
Kotlin/src/com/gildedrose/GildedRose.kt
Normal 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
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
19
Kotlin/src/com/gildedrose/GildedRoseTest.kt
Normal file
19
Kotlin/src/com/gildedrose/GildedRoseTest.kt
Normal 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)
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
3
Kotlin/src/com/gildedrose/Item.kt
Normal file
3
Kotlin/src/com/gildedrose/Item.kt
Normal file
@ -0,0 +1,3 @@
|
||||
package com.gildedrose
|
||||
|
||||
data class Item(var name: String, var sellIn: Int, var quality: Int)
|
||||
36
Kotlin/src/com/gildedrose/TexttestFixture.kt
Normal file
36
Kotlin/src/com/gildedrose/TexttestFixture.kt
Normal 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()
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user