Skip to content
Snippets Groups Projects
Verified Commit 6487985e authored by Mirio Eggmann's avatar Mirio Eggmann :zap:
Browse files

add conjured item

parent 814e49aa
No related branches found
No related tags found
No related merge requests found
......@@ -6,6 +6,7 @@ class GildedRose {
private static final String BACKSTAGE_PASSES = "Backstage passes to a TAFKAL80ETC concert";
private static final String SULFURAS = "Sulfuras, Hand of Ragnaros";
private static final String AGED_BRIE = "Aged Brie";
private static final String CONJURED = "Conjured Mana Cake";
public GildedRose(Item[] items) {
this.items = items;
......@@ -17,7 +18,9 @@ class GildedRose {
updateQualityAgedBrie(item);
} else if (item.name.equals(BACKSTAGE_PASSES)) {
updateQualityBackstagePasses(item);
} else if (!item.name.equals(SULFURAS)) {
} else if (item.name.equals(CONJURED)) {
updateQualityConjured(item);
}else if (!item.name.equals(SULFURAS)) {
updateQualityOtherItems(item);
}
}
......@@ -59,6 +62,16 @@ class GildedRose {
}
}
private void updateQualityConjured(Item item) {
if (item.quality > 0) {
item.quality -= 2;
}
updateSellIn(item);
if (item.sellIn < 0 && item.quality > 0) {
item.quality -= 2;
}
}
private void updateSellIn(Item item) {
if (!item.name.equals(SULFURAS)) {
item.sellIn--;
......
......@@ -111,6 +111,7 @@ class GildedRoseTest {
assertEquals(-1, backstagePasses.sellIn);
}
// Other items degrade in quality by one in one day
@Test
void testUpdateQualityForOtherItem() {
var normalItem = new Item("Other Item", 10, 10);
......@@ -121,4 +122,17 @@ class GildedRoseTest {
assertEquals(9, normalItem.quality);
assertEquals(9, normalItem.sellIn);
}
// "Conjured" items degrade in Quality twice as fast as normal items
@Test
void testUpdateQualityForConjuredItem() {
var conjuredItem = new Item("Conjured Mana Cake", 10, 10);
GildedRose gildedRose = new GildedRose(new Item[]{conjuredItem});
gildedRose.updateQuality();
assertEquals(8, conjuredItem.quality);
assertEquals(9, conjuredItem.sellIn);
}
}
......@@ -13,7 +13,6 @@ public class TexttestFixture {
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) };
GildedRose app = new GildedRose(items);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment