diff --git a/.idea/modules.xml b/.idea/modules.xml index 4278bcdd..75acca37 100644 --- a/.idea/modules.xml +++ b/.idea/modules.xml @@ -5,5 +5,4 @@ - - + \ No newline at end of file diff --git a/Groovy/.gitignore b/Groovy/.gitignore new file mode 100644 index 00000000..8f0aaba4 --- /dev/null +++ b/Groovy/.gitignore @@ -0,0 +1,124 @@ + +# Created by https://www.gitignore.io/api/groovy,intellij,eclipse,vim + +#!! ERROR: groovy is undefined. Use list command to see defined gitignore types !!# + +### Intellij ### +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff: +.idea/workspace.xml +.idea/tasks.xml +.idea/dictionaries +.idea/vcs.xml +.idea/jsLibraryMappings.xml + +# Sensitive or high-churn files: +.idea/dataSources.ids +.idea/dataSources.xml +.idea/dataSources.local.xml +.idea/sqlDataSources.xml +.idea/dynamic.xml +.idea/uiDesigner.xml + +# Gradle: +.idea/gradle.xml +.idea/libraries + +# Mongo Explorer plugin: +.idea/mongoSettings.xml + +## File-based project format: +*.iws + +## Plugin-specific files: + +# IntelliJ +/out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +### Intellij Patch ### +# Comment Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-215987721 + +# *.iml +# modules.xml + + +### Eclipse ### + +.metadata +bin/ +tmp/ +*.tmp +*.bak +*.swp +*~.nib +local.properties +.settings/ +.loadpath +.recommenders + +# Eclipse Core +.project + +# External tool builders +.externalToolBuilders/ + +# Locally stored "Eclipse launch configurations" +*.launch + +# PyDev specific (Python IDE for Eclipse) +*.pydevproject + +# CDT-specific (C/C++ Development Tooling) +.cproject + +# JDT-specific (Eclipse Java Development Tools) +.classpath + +# Java annotation processor (APT) +.factorypath + +# PDT-specific (PHP Development Tools) +.buildpath + +# sbteclipse plugin +.target + +# Tern plugin +.tern-project + +# TeXlipse plugin +.texlipse + +# STS (Spring Tool Suite) +.springBeans + +# Code Recommenders +.recommenders/ + + +### Vim ### +# swap +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +# session +Session.vim +# temporary +.netrwhist +*~ +# auto-generated tag files +tags + diff --git a/Groovy/.idea/compiler.xml b/Groovy/.idea/compiler.xml new file mode 100644 index 00000000..96cc43ef --- /dev/null +++ b/Groovy/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Groovy/.idea/copyright/profiles_settings.xml b/Groovy/.idea/copyright/profiles_settings.xml new file mode 100644 index 00000000..e7bedf33 --- /dev/null +++ b/Groovy/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/Groovy/.idea/misc.xml b/Groovy/.idea/misc.xml new file mode 100644 index 00000000..c6d8fb73 --- /dev/null +++ b/Groovy/.idea/misc.xml @@ -0,0 +1,26 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Groovy/.idea/modules.xml b/Groovy/.idea/modules.xml new file mode 100644 index 00000000..c1a39855 --- /dev/null +++ b/Groovy/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Groovy/Groovy.iml b/Groovy/Groovy.iml new file mode 100644 index 00000000..85bea791 --- /dev/null +++ b/Groovy/Groovy.iml @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/Groovy/readme.txt b/Groovy/readme.txt new file mode 100644 index 00000000..1f869aac --- /dev/null +++ b/Groovy/readme.txt @@ -0,0 +1,8 @@ +Welcome to the Groovy Gilded Rose +================================= + +to run the tests, you can either: +- run them from your favorite IDE +- run them from the src/ folder in your shell: + - $ groovy com/gildedrose/GildedRoseTest.groovy + diff --git a/Groovy/src/com/gildedrose/GildedRose.groovy b/Groovy/src/com/gildedrose/GildedRose.groovy new file mode 100644 index 00000000..ba054cb6 --- /dev/null +++ b/Groovy/src/com/gildedrose/GildedRose.groovy @@ -0,0 +1,62 @@ +package com.gildedrose + +class GildedRose { + Item[] items + + GildedRose(Item[] items) { + this.items = items + } + + void updateQuality() { + for (int i = 0; i < items.length; i++) { + 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/Groovy/src/com/gildedrose/GildedRoseTest.groovy b/Groovy/src/com/gildedrose/GildedRoseTest.groovy new file mode 100644 index 00000000..d96202c0 --- /dev/null +++ b/Groovy/src/com/gildedrose/GildedRoseTest.groovy @@ -0,0 +1,15 @@ +package com.gildedrose + +import org.junit.Test + +class GildedRoseTest { + + @Test + void "foo"() { + def items = [ new Item("foo", 0, 0) ] as Item[] + def app = new GildedRose(items) + app.updateQuality() + assert "fixme" == app.items[0].name + } + +} diff --git a/Groovy/src/com/gildedrose/Item.groovy b/Groovy/src/com/gildedrose/Item.groovy new file mode 100644 index 00000000..c42d6cea --- /dev/null +++ b/Groovy/src/com/gildedrose/Item.groovy @@ -0,0 +1,21 @@ +package com.gildedrose + +class Item { + + String name + + int sellIn + + int quality + + Item(String name, int sellIn, int quality) { + this.name = name + this.sellIn = sellIn + this.quality = quality + } + + @Override + String toString() { + return this.name + ", " + this.sellIn + ", " + this.quality + } +} diff --git a/Groovy/src/com/gildedrose/TexttestFixture.groovy b/Groovy/src/com/gildedrose/TexttestFixture.groovy new file mode 100644 index 00000000..3c8b46e3 --- /dev/null +++ b/Groovy/src/com/gildedrose/TexttestFixture.groovy @@ -0,0 +1,32 @@ +package com.gildedrose + +println("OMGHAI!") + +Item[] items = [ + new Item("+5 Dexterity Vest", 10, 20), + new Item("Aged Brie", 2, 0), + new Item("Elixir of the Mongoose", 5, 7), + new Item("Sulfuras, Hand of Ragnaros", 0, 80), + new Item("Sulfuras, Hand of Ragnaros", -1, 80), + new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20), + new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49), + new Item("Backstage passes to a TAFKAL80ETC concert", 5, 49), + // this conjured item does not work properly yet + new Item("Conjured Mana Cake", 3, 6)] as Item[] + +GildedRose app = new GildedRose(items) + +int days = 2 +if (args.length > 0) { + days = Integer.parseInt(args[0]) + 1 +} + +for (int i = 0; i < days; i++) { + println("-------- day " + i + " --------") + println("name, sellIn, quality") + for (Item item in items) { + println(item) + } + println "" + app.updateQuality() +}