mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
add tests for conjured before sellIn date is non zero
This commit is contained in:
parent
5ed7391ddb
commit
eb48f26dc3
@ -9,52 +9,71 @@ class GildedRose {
|
||||
|
||||
public void updateQuality() {
|
||||
for (Item item : items) {
|
||||
if (!item.name.equals("Aged Brie")
|
||||
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality = item.quality - 1;
|
||||
if (item.name.equals("Conjured Mana Cake")) {
|
||||
updateQualityForConjured(item);
|
||||
} else
|
||||
updateQuality(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void updateQualityForConjured(Item item) {
|
||||
if (item.sellIn > 0) {
|
||||
|
||||
item.quality = degradeQualityBy(item.quality, 2);
|
||||
}
|
||||
item.sellIn = item.sellIn - 1;
|
||||
}
|
||||
|
||||
private Integer degradeQualityBy(int currentQuality, int degradeBy) {
|
||||
return Math.max(currentQuality - degradeBy, 0);
|
||||
}
|
||||
|
||||
private void updateQuality(Item item) {
|
||||
if (!item.name.equals("Aged Brie")
|
||||
&& !item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality = item.quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
|
||||
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.sellIn < 11) {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.sellIn < 6) {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.sellIn = item.sellIn - 1;
|
||||
}
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (!item.name.equals("Aged Brie")) {
|
||||
if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality = item.quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item.quality = 0;
|
||||
}
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
|
||||
if (item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.sellIn < 11) {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (item.sellIn < 6) {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.sellIn = item.sellIn - 1;
|
||||
}
|
||||
|
||||
if (item.sellIn < 0) {
|
||||
if (!item.name.equals("Aged Brie")) {
|
||||
if (!item.name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (item.quality > 0) {
|
||||
if (!item.name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
item.quality = item.quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item.quality = 0;
|
||||
}
|
||||
} else {
|
||||
if (item.quality < 50) {
|
||||
item.quality = item.quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -14,14 +14,32 @@ class GildedRoseTest {
|
||||
private static Stream<Arguments> provideInputWhereSellInDayPassesByOneDay() {
|
||||
|
||||
return Stream.of(
|
||||
//1. Normal item
|
||||
//1.a Before sellIn
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Normal Item", 1, 0)}), "Normal Item", 0, 0),
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Normal Item", 1, 10)}), "Normal Item", 0, 9),
|
||||
|
||||
//1.b after sellIn
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Normal Item", 0, 0)}), "Normal Item", -1, 0),
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Normal Item", 0, 10)}), "Normal Item", -1, 8),
|
||||
|
||||
//1. Conjured item
|
||||
//1.a Before sellIn
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Conjured Mana Cake", 1, 10)}), "Conjured Mana Cake", 0, 8),
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Conjured Mana Cake", 1, 0)}), "Conjured Mana Cake", 0, 0),
|
||||
|
||||
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("+5 Dexterity Vest", 10, 20)}), "+5 Dexterity Vest", 9, 19),
|
||||
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Aged Brie", 2, 0)}), "Aged Brie", 1, 1),
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Aged Brie", 1, 0)}), "Aged Brie", 0, 1),
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Aged Brie", 1, 50)}), "Aged Brie", 0, 50),
|
||||
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Elixir of the Mongoose", 5, 7)}), "Elixir of the Mongoose", 4, 6),
|
||||
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Sulfuras, Hand of Ragnaros", 0, 80)}), "Sulfuras, Hand of Ragnaros", 0, 80),
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Sulfuras, Hand of Ragnaros", -1, 80)}), "Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Backstage passes to a TAFKAL80ETC concert", 15, 20)}), "Backstage passes to a TAFKAL80ETC concert", 14, 21),
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49)}), "Backstage passes to a TAFKAL80ETC concert", 9, 50),
|
||||
Arguments.of(new GildedRose(new Item[]{new Item("Backstage passes to a TAFKAL80ETC concert", 10, 49)}), "Backstage passes to a TAFKAL80ETC concert", 9, 50),
|
||||
|
||||
Loading…
Reference in New Issue
Block a user