diff --git a/Java/README.md b/Java/README.md index da5135ae..b9166802 100644 --- a/Java/README.md +++ b/Java/README.md @@ -17,18 +17,22 @@
  • 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.
  • - - -

    New Requisites

    - + +

    New Requirement

    + @@ -42,7 +46,6 @@

    Original Output

    -
    OMGHAI!
    -------- day 0 --------
    diff --git a/Java/src/test/java/com/gildedrose/GildedRoseTest.java b/Java/src/test/java/com/gildedrose/GildedRoseTest.java index 9e61b788..d2ca9a49 100644 --- a/Java/src/test/java/com/gildedrose/GildedRoseTest.java +++ b/Java/src/test/java/com/gildedrose/GildedRoseTest.java @@ -7,21 +7,80 @@ import java.util.stream.IntStream; import static org.junit.jupiter.api.Assertions.assertEquals; class GildedRoseTest { + private final int days = 2; @Test - void dexterityVestShouldDecreaseSellInAndQualityEachUpdate() { - String name = "+5 Dexterity Vest"; - int sellIn = 10; - int quality = 20; - int days = 2; + void shouldDecreaseQualityEachUpdate() { + assertCalculatedValues(getDecreaseQualityItems(), + new GildedRose(getDecreaseQualityItems()), CalcQuality.DECREASE); + } - Item[] items = new Item[]{new Item(name, sellIn, quality)}; - GildedRose app = new GildedRose(items); - IntStream.rangeClosed(1, days).forEach(index -> { + @Test + void shouldIncreaseQualityEachUpdate() { + assertCalculatedValues(getIncreaseQualityItems(), + new GildedRose(getIncreaseQualityItems()), CalcQuality.INCREASE); + } + + @Test + void shouldRetainPropsEachUpdate() { + assertCalculatedValues(getRetainPropsItems(), + new GildedRose(getRetainPropsItems()), CalcQuality.NOTHING); + } + + private Item[] getRetainPropsItems() { + return new Item[] { + new Item("Sulfuras, Hand of Ragnaros", 0, 80), + new Item("Sulfuras, Hand of Ragnaros", -1, 80) + }; + } + + private Item[] getIncreaseQualityItems() { + return new Item[] { + new Item("Aged Brie", 2, 0), + 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) + }; + } + + private Item[] getDecreaseQualityItems() { + return new Item[] { + new Item("+5 Dexterity Vest", 10, 20), + new Item("Elixir of the Mongoose", 5, 7) + }; + } + + private void assertCalculatedValues(Item[] originItems, GildedRose app, CalcQuality calcQuality) { + IntStream.range(1, this.days).forEach(day -> { app.updateQuality(); - assertEquals(name, app.items[0].name); - assertEquals(sellIn - index, app.items[0].sellIn); - assertEquals(quality - index, app.items[0].quality); + IntStream.range(0, originItems.length).forEach(index -> { + assertEquals(originItems[index].name, app.items[index].name); + int sellInCalculated = getSellInCalculated(originItems[index].sellIn, calcQuality, day); + assertEquals(sellInCalculated, app.items[index].sellIn); + int quantityCalculated = getQualityCalculated(originItems[index].quality, calcQuality, day); + assertEquals(quantityCalculated, app.items[index].quality); + }); }); } + + private int getSellInCalculated(int sellIn, CalcQuality calcQuality, int day) { + if(!calcQuality.equals(CalcQuality.NOTHING)) { + return sellIn - day; + } + return sellIn; + } + + private int getQualityCalculated(int quality, CalcQuality calcQuality, int day) { + if(calcQuality.equals(CalcQuality.DECREASE)) { + return quality - day; + } + if(calcQuality.equals(CalcQuality.INCREASE)) { + return quality + day; + } + return quality; + } +} + +enum CalcQuality { + INCREASE, DECREASE, NOTHING }