mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-19 16:31:30 +00:00
- Group actual system information in README.md;
- Create tests based on TexttestFixture class;
This commit is contained in:
parent
b12a345e6c
commit
deb9a3a5c9
@ -17,18 +17,22 @@
|
|||||||
</li>
|
</li>
|
||||||
<li>All items have a Quality value which denotes how valuable the item is.</li>
|
<li>All items have a Quality value which denotes how valuable the item is.</li>
|
||||||
<li>At the end of each day our system lowers both values for every item.</li>
|
<li>At the end of each day our system lowers both values for every item.</li>
|
||||||
</ul>
|
|
||||||
|
|
||||||
<h3>New Requisites</h3>
|
|
||||||
<ul>
|
|
||||||
<li>Once the sell by date has passed, Quality degrades twice as fast</li>
|
<li>Once the sell by date has passed, Quality degrades twice as fast</li>
|
||||||
<li>The Quality of an item is never negative</li>
|
<li>The Quality of an item is never negative</li>
|
||||||
<li>"Aged Brie" actually increases in Quality the older it gets</li>
|
<li>"Aged Brie" actually increases in Quality the older it gets</li>
|
||||||
<li>The Quality of an item is never more than 50</li>
|
<li>The Quality of an item is never more than 50</li>
|
||||||
<li>"Sulfuras", being a legendary item, never has to be sold or decreases in Quality</li>
|
<li>"Sulfuras", being a legendary item, never has to be sold or decreases in Quality</li>
|
||||||
<li>"Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;</li>
|
<li>
|
||||||
<li>Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but</li>
|
"Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;
|
||||||
<li>Quality drops to 0 after the concert</li>
|
<ul>
|
||||||
|
<li>Quality increases by 2 when there are 10 days or less and by 3 when there are 5 days or less but</li>
|
||||||
|
<li>Quality drops to 0 after the concert</li>
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
|
</ul>
|
||||||
|
|
||||||
|
<h3>New Requirement</h3>
|
||||||
|
<ul>
|
||||||
<li>Conjured" items degrade in Quality twice as fast as normal items</li>
|
<li>Conjured" items degrade in Quality twice as fast as normal items</li>
|
||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
@ -42,7 +46,6 @@
|
|||||||
</ul>
|
</ul>
|
||||||
|
|
||||||
<h3>Original Output</h3>
|
<h3>Original Output</h3>
|
||||||
|
|
||||||
<div>OMGHAI!</div>
|
<div>OMGHAI!</div>
|
||||||
<div>-------- day 0 --------</div>
|
<div>-------- day 0 --------</div>
|
||||||
<table>
|
<table>
|
||||||
|
|||||||
@ -7,21 +7,80 @@ import java.util.stream.IntStream;
|
|||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
class GildedRoseTest {
|
class GildedRoseTest {
|
||||||
|
private final int days = 2;
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void dexterityVestShouldDecreaseSellInAndQualityEachUpdate() {
|
void shouldDecreaseQualityEachUpdate() {
|
||||||
String name = "+5 Dexterity Vest";
|
assertCalculatedValues(getDecreaseQualityItems(),
|
||||||
int sellIn = 10;
|
new GildedRose(getDecreaseQualityItems()), CalcQuality.DECREASE);
|
||||||
int quality = 20;
|
}
|
||||||
int days = 2;
|
|
||||||
|
|
||||||
Item[] items = new Item[]{new Item(name, sellIn, quality)};
|
@Test
|
||||||
GildedRose app = new GildedRose(items);
|
void shouldIncreaseQualityEachUpdate() {
|
||||||
IntStream.rangeClosed(1, days).forEach(index -> {
|
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();
|
app.updateQuality();
|
||||||
assertEquals(name, app.items[0].name);
|
IntStream.range(0, originItems.length).forEach(index -> {
|
||||||
assertEquals(sellIn - index, app.items[0].sellIn);
|
assertEquals(originItems[index].name, app.items[index].name);
|
||||||
assertEquals(quality - index, app.items[0].quality);
|
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
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user