mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 12:22:12 +00:00
first hack at a version for each language, translated from the C#.
This commit is contained in:
parent
926f8a2686
commit
e8e5e0223f
99
GildedRose/Java/GildedRose.java
Normal file
99
GildedRose/Java/GildedRose.java
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
|
||||||
|
class GildedRose {
|
||||||
|
List<Item> items;
|
||||||
|
|
||||||
|
public static void Main(string[] args) {
|
||||||
|
System.out.println("OMGHAI!");
|
||||||
|
|
||||||
|
List<Item> items = new List<Item> {
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
14
GildedRose/Java/Item.java
Normal file
14
GildedRose/Java/Item.java
Normal file
@ -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;
|
||||||
|
}
|
||||||
|
}
|
||||||
28
GildedRose/README
Normal file
28
GildedRose/README
Normal file
@ -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.
|
||||||
117
GildedRose/cpp/GildedRose.cc
Normal file
117
GildedRose/cpp/GildedRose.cc
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
#include <gtest/gtest.h>
|
||||||
|
|
||||||
|
void example()
|
||||||
|
{
|
||||||
|
std::list<Item> items = new std::list<Item>();
|
||||||
|
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<Item> 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<Item> items = new std::list<Item>();
|
||||||
|
items.push_back(new Item("Foo", 0, 0));
|
||||||
|
GildedRose app = new GildedRose(items);
|
||||||
|
app.updateQuality();
|
||||||
|
EXPECT_EQ("fixme", app.items[0].name);
|
||||||
|
}
|
||||||
|
|
||||||
48
GildedRose/python/gilded_rose.py
Normal file
48
GildedRose/python/gilded_rose.py
Normal file
@ -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)
|
||||||
6
GildedRose/python/test_gilded_rose.py
Normal file
6
GildedRose/python/test_gilded_rose.py
Normal file
@ -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
|
||||||
Loading…
Reference in New Issue
Block a user