diff --git a/GildedRose/Java/GildedRose.java b/GildedRose/Java/GildedRose.java new file mode 100644 index 00000000..ed89f8a4 --- /dev/null +++ b/GildedRose/Java/GildedRose.java @@ -0,0 +1,99 @@ + +class GildedRose { + List items; + + public static void Main(string[] args) { + System.out.println("OMGHAI!"); + + List items = new List { + 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("Backstage passes to a TAFKAL80ETC concert", 15, 20), + new Item("Conjured Mana Cake", 3, 6) + } + + GildedRose app = new GildedRose(items); + + app.updateQuality(); + + } + + public void updateQuality() { + for (int i = 0; i < items.length; i++) + { + if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert") + { + if (items[i].quality > 0) + { + if (items[i].name != "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 == "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 != "Sulfuras, Hand of Ragnaros") + { + items[i].sellIn = items[i].sellIn - 1; + } + + if (items[i].sellIn < 0) + { + if (items[i].name != "Aged Brie") + { + if (items[i].name != "Backstage passes to a TAFKAL80ETC concert") + { + if (items[i].quality > 0) + { + if (items[i].name != "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/GildedRose/Java/Item.java b/GildedRose/Java/Item.java new file mode 100644 index 00000000..afe3ef8f --- /dev/null +++ b/GildedRose/Java/Item.java @@ -0,0 +1,14 @@ +public class Item { + + public String name; + + public int sellIn; + + public int quality; + + public Item(String name, int sellIn, int quality) { + this.name = name; + this.sellIn = sellIn; + this.quality = quality; + } +} diff --git a/GildedRose/README b/GildedRose/README new file mode 100644 index 00000000..22bc5233 --- /dev/null +++ b/GildedRose/README @@ -0,0 +1,28 @@ +(This Kata is already on GitHub as "GildedRose" with several forks, and I'm not sure who put it up there first. All the forks I could find were pure C# so rather than fork one of them I decided to just put other languages in here.) + +================ +Gilded Rose Kata +================ + +Hi and welcome to team Gilded Rose. As you know, we are a small inn with a prime location in a prominent city ran by a friendly innkeeper named Allison. We also buy and sell only the finest goods. Unfortunately, our goods are constantly degrading in quality as they approach their sell by date. We have a system in place that updates our inventory for us. It was developed by a no-nonsense type named Leeroy, who has moved on to new adventures. Your task is to add the new feature to our system so that we can begin selling a new category of items. First an introduction to our system: + + - All items have a SellIn value which denotes the number of days we have to sell the item + - All items have a Quality value which denotes how valuable the item is + - At the end of each day our system lowers both values for every item + +Pretty simple, right? Well this is where it gets interesting: + + - Once the sell by date has passed, Quality degrades twice as fast + - The Quality of an item is never negative + - "Aged Brie" actually increases in Quality the older it gets + - The Quality of an item is never more than 50 + - "Sulfuras", being a legendary item, never has to be sold or decreases in Quality + - "Backstage passes", like aged brie, increases in Quality as it's SellIn value approaches; Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but Quality drops to 0 after the concert + +We have recently signed a supplier of conjured items. This requires an update to our system: + + - "Conjured" items degrade in Quality twice as fast as normal items + +Feel free to make any changes to the UpdateQuality method and add any new code as long as everything still works correctly. However, do not alter the Item class or Items property as those belong to the goblin in the corner who will insta-rage and one-shot you as he doesn't believe in shared code ownership (you can make the UpdateQuality method and Items property static if you like, we'll cover for you). Your work needs to be completed by Friday, February 18, 2011 08:00:00 AM PST. + +Just for clarification, an item can never have its Quality increase above 50, however "Sulfuras" is a legendary item and as such its Quality is 80 and it never alters. \ No newline at end of file diff --git a/GildedRose/cpp/GildedRose.cc b/GildedRose/cpp/GildedRose.cc new file mode 100644 index 00000000..fa001b07 --- /dev/null +++ b/GildedRose/cpp/GildedRose.cc @@ -0,0 +1,117 @@ +#include + +void example() +{ + std::list items = new std::list(); + items.push_back(new Item("+5 Dexterity Vest", 10, 20)); + items.push_back(new Item("Aged Brie", 2, 0)); + items.push_back(new Item("Elixir of the Mongoose", 5, 7)); + items.push_back(new Item("Sulfuras, Hand of Ragnaros", 0, 80)); + items.push_back(new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)); + items.push_back(new Item("Conjured Mana Cake", 3, 6)); + GildedRose app = new GildedRose(items); + app.updateQuality(); +} + +class GildedRose +{ +public: + std::list items; + GildedRose(std::list items) + { + this.items = items; + } + + void updateQuality() + { + for (int i = 0; i < items.length; i++) + { + if (items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert") + { + if (items[i].quality > 0) + { + if (items[i].name != "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 == "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 != "Sulfuras, Hand of Ragnaros") + { + items[i].sellIn = items[i].sellIn - 1; + } + + if (items[i].sellIn < 0) + { + if (items[i].name != "Aged Brie") + { + if (items[i].name != "Backstage passes to a TAFKAL80ETC concert") + { + if (items[i].quality > 0) + { + if (items[i].name != "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; + } + } + } + } + } +}; + +class Item +{ +public: + std::string name; + int sellIn; + int quality; +}; + +TEST(GildedRoseTest, Foo) { + std::list items = new std::list(); + items.push_back(new Item("Foo", 0, 0)); + GildedRose app = new GildedRose(items); + app.updateQuality(); + EXPECT_EQ("fixme", app.items[0].name); +} + diff --git a/GildedRose/python/gilded_rose.py b/GildedRose/python/gilded_rose.py new file mode 100644 index 00000000..a518844e --- /dev/null +++ b/GildedRose/python/gilded_rose.py @@ -0,0 +1,48 @@ + +def update_quality(items): + for item in items: + if item.name != "Aged Brie" and item.name != "Backstage passes to a TAFKAL80ETC concert": + if item.quality > 0: + if item.name != "Sulfuras, Hand of Ragnaros": + item.quality = item.quality - 1; + else: + if item.quality < 50: + item.quality = item.quality + 1; + if item.name == "Backstage passes to a TAFKAL80ETC concert": + if item.sell_in < 11: + if item.quality < 50: + item.quality = item.quality + 1; + if item.sell_in < 6: + if item.quality < 50: + item.quality = item.quality + 1; + if item.name != "Sulfuras, Hand of Ragnaros": + item.sell_in = item.sell_in - 1; + if item.sell_in < 0: + if item.name != "Aged Brie": + if item.name != "Backstage passes to a TAFKAL80ETC concert": + if item.quality > 0: + if item.name != "Sulfuras, Hand of Ragnaros": + item.quality = item.quality - 1; + else: + item.quality = item.quality - item.quality; + else: + if item.quality < 50: + item.quality = item.quality + 1; + return items + +class Item: + def __init__(self, name, sell_in, quality): + self.name = name + self.sell_in = sell_in + self.quality = quality + +if __name__ == "__main__": + items = [ + Item(name="+5 Dexterity Vest", sell_in=10, quality=20), + Item(name="Aged Brie", sell_in=2, quality=0), + Item(name="Elixir of the Mongoose", sell_in=5, quality=7), + Item(name="Sulfuras, Hand of Ragnaros", sell_in=0, quality=80), + Item(name="Backstage passes to a TAFKAL80ETC concert", sell_in=15, quality=20), + Item(name="Conjured Mana Cake", sell_in=3, quality=6), + ] + update_quality(items) \ No newline at end of file diff --git a/GildedRose/python/test_gilded_rose.py b/GildedRose/python/test_gilded_rose.py new file mode 100644 index 00000000..34304cdb --- /dev/null +++ b/GildedRose/python/test_gilded_rose.py @@ -0,0 +1,6 @@ +from gilded_rose import Item, update_quality + +def test_foo(): + items = [Item("foo", 0, 0)] + update_quality(items) + assert "fixme" == items[0].name \ No newline at end of file diff --git a/README b/README index 46e9722c..9e44d8ec 100644 --- a/README +++ b/README @@ -2,4 +2,5 @@ This is a collection of starting files for when practicing refactoring. Contents so far: -Tennis kata in Java and python. \ No newline at end of file +Tennis Kata in Java, Python and C++. +GildedRose Kata in Java, Python and C++. (a C# version is already available on github) \ No newline at end of file