mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41: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>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>
|
||||
</ul>
|
||||
|
||||
<h3>New Requisites</h3>
|
||||
<ul>
|
||||
<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>"Aged Brie" actually increases in Quality the older it gets</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>"Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;</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>
|
||||
<li>Quality drops to 0 after the concert</li>
|
||||
<li>
|
||||
"Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;
|
||||
<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>
|
||||
</ul>
|
||||
|
||||
@ -42,7 +46,6 @@
|
||||
</ul>
|
||||
|
||||
<h3>Original Output</h3>
|
||||
|
||||
<div>OMGHAI!</div>
|
||||
<div>-------- day 0 --------</div>
|
||||
<table>
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user