mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Merge pull request #3 from pcroch/refactor/refactoring_the_updateQuality_Class
Refactor/refactoring the update quality class
This commit is contained in:
commit
327d26c7dd
@ -9,58 +9,41 @@ class GildedRose {
|
||||
|
||||
public void updateQuality() {
|
||||
for (int i = 0; i < items.length; i++) {
|
||||
if (!items[i].name.equals("Aged Brie")
|
||||
&& !items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].quality > 0) {
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].quality = items[i].quality - 1;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
|
||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].sellIn < 11) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 6) {
|
||||
if (items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].sellIn = items[i].sellIn - 1;
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 0) {
|
||||
if (!items[i].name.equals("Aged Brie")) {
|
||||
if (!items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].quality > 0) {
|
||||
if (!items[i].name.equals("Sulfuras, Hand of Ragnaros")) {
|
||||
items[i].quality = items[i].quality - 1;
|
||||
}
|
||||
}
|
||||
if ("Sulfuras, Hand of Ragnaros".equals(items[i].name)) {
|
||||
continue;
|
||||
} else if ("Conjured Mana Cake".equals(items[i].name)) {
|
||||
while (items[i].quality > 0) {
|
||||
if (items[i].sellIn >= 0) {
|
||||
items[i].quality = items[i].quality - 2;
|
||||
} else {
|
||||
items[i].quality = items[i].quality - items[i].quality;
|
||||
items[i].quality = items[i].quality - 4;
|
||||
}
|
||||
} else {
|
||||
if (items[i].quality < 50) {
|
||||
}
|
||||
items[i].sellIn = items[i].sellIn - 1;
|
||||
continue;
|
||||
} else if ("Backstage passes to a TAFKAL80ETC concert".equals(items[i].name) | "Aged Brie".equals(items[i].name)) {
|
||||
while (items[i].quality < 50) {
|
||||
if ("Backstage passes to a TAFKAL80ETC concert".equals(items[i].name) & items[i].sellIn <= 5) {
|
||||
items[i].quality = items[i].quality + 3;
|
||||
} else if ("Backstage passes to a TAFKAL80ETC concert".equals(items[i].name) & items[i].sellIn < 10) {
|
||||
items[i].quality = items[i].quality + 2;
|
||||
} else {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
}
|
||||
items[i].sellIn = items[i].sellIn - 1;
|
||||
continue;
|
||||
} else {
|
||||
// last case
|
||||
while (items[i].quality > 0) {
|
||||
if (items[i].sellIn >= 0) {
|
||||
items[i].quality = items[i].quality - 2;
|
||||
} else {
|
||||
items[i].quality = items[i].quality - 4;
|
||||
}
|
||||
}
|
||||
items[i].sellIn = items[i].sellIn - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updateQuantities(){
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ class UpdateQualityTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void qualityIteNeverNegatif() {
|
||||
void qualityItemNeverNegatif() {
|
||||
System.out.println("The Quality of an item is never negative");
|
||||
Item[] items = new Item[]{new Item("+5 Dexterity Vest", 10, 1)};
|
||||
GildedRose app = new GildedRose(items);
|
||||
@ -56,6 +56,33 @@ class UpdateQualityTest {
|
||||
assertEquals("+5 Dexterity Vest", app.items[0].name);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sellInValueCanBeNegative() {
|
||||
System.out.println("SellIn value of an Item can be negative until quality reach zero");
|
||||
Item[] items = new Item[]{new Item("+5 Dexterity Vest", 0, 30)};
|
||||
GildedRose app = new GildedRose(items);
|
||||
int timeFrame = 10;
|
||||
for (int i = 0; i < timeFrame; i++) {
|
||||
app.updateQuality();
|
||||
}
|
||||
assertEquals(10, app.items[0].quality);
|
||||
assertEquals(-timeFrame, app.items[0].sellIn);
|
||||
}
|
||||
|
||||
@Test
|
||||
void sellInValueCanNotBeNegatifForSulfuras() {
|
||||
System.out.println("SellIn value of Sulfuras Item can not be negative bcse quality never decreases");
|
||||
Item[] items = new Item[]{new Item("Sulfuras, Hand of Ragnaros", -1, 80)};
|
||||
GildedRose app = new GildedRose(items);
|
||||
int timeFrame = 10;
|
||||
for (int i = 0; i < timeFrame; i++) {
|
||||
app.updateQuality();
|
||||
}
|
||||
assertEquals(80, app.items[0].quality); // if time is > 1
|
||||
assertEquals(-1, app.items[0].sellIn);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void agedBrieQualityIncreaseWthIteration() {
|
||||
System.out.println("\"Aged Brie\" actually increases in Quality the older it gets");
|
||||
@ -99,15 +126,15 @@ class UpdateQualityTest {
|
||||
|
||||
|
||||
@Test
|
||||
void itemSulfurasNotDecreasedQuality() {
|
||||
System.out.println("\"Sulfuras\", being a legendary item, never decreases in Quality");
|
||||
Item[] items = new Item[]{new Item("Sulfuras, Hand of Ragnaros", 5, 79)};
|
||||
void itemSulfurasNotChangeQuality() {
|
||||
System.out.println("\"Sulfuras\", being a legendary item, never decreases in Quality and stays the same");
|
||||
Item[] items = new Item[]{new Item("Sulfuras, Hand of Ragnaros", 5, 44)};
|
||||
GildedRose app = new GildedRose(items);
|
||||
assertEquals("Sulfuras, Hand of Ragnaros", app.items[0].name);
|
||||
for (int i = 0; i < 10; i++) {
|
||||
app.updateQuality();
|
||||
}
|
||||
assertEquals(79, app.items[0].quality);
|
||||
assertEquals(44, app.items[0].quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -136,6 +163,23 @@ class UpdateQualityTest {
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
for (int i = 0; i < 2; i++) {
|
||||
assertEquals(6, app.items[i].quality);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemBackstageQualityDropsToZeroAfterTheConcert() {
|
||||
System.out.println("Quality drops to 0 after the concert");
|
||||
Item[] items = new Item[]{
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 0, 2),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 0, 3),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 0, 7)
|
||||
};
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
for (Item el : items) {
|
||||
assertEquals(0, el.quality);
|
||||
}
|
||||
}
|
||||
|
||||
@ -145,8 +189,8 @@ class UpdateQualityTest {
|
||||
|
||||
|
||||
@Test
|
||||
void itemConjuredQualityTwiceAsFastAsNormalItems() {
|
||||
System.out.println("\"Conjured\" items degrade in Quality twice as fast as normal items");
|
||||
void itemConjuredQualityTwiceAsFastAsNormalItemsWithPositiveSellIn() {
|
||||
System.out.println("\"Conjured\" items degrade in Quality twice as fast as normal items when sellin is positive");
|
||||
Item[] items = new Item[]{
|
||||
new Item("Conjured Mana Cake", 3, 6)};
|
||||
GildedRose app = new GildedRose(items);
|
||||
@ -154,6 +198,28 @@ class UpdateQualityTest {
|
||||
assertEquals(4, app.items[0].quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemConjuredQualityTwiceAsFastAsNormalItemsWhenSellInIsZero() {
|
||||
System.out.println("\"Conjured\" items degrade in Quality twice as fast as normal items when sellin is wero");
|
||||
Item[] items = new Item[]{
|
||||
new Item("Conjured Mana Cake", 0, 10)
|
||||
};
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
assertEquals(8, app.items[0].quality);
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemConjuredQualityTwiceAsFastAsNormalItemsWithNegativeSellIn() {
|
||||
System.out.println("\"Conjured\" items degrade in Quality twice as fast as normal items when sellin is negtive");
|
||||
Item[] items = new Item[]{
|
||||
new Item("Conjured Mana Cake", -1, 8)
|
||||
};
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
assertEquals(4, app.items[0].quality);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,64 +0,0 @@
|
||||
package com.gildedrose;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
|
||||
/**
|
||||
* Testing for Selling items
|
||||
*/
|
||||
|
||||
class updateQuantitiesTest {
|
||||
@Test
|
||||
void itemsSoldAfterConcert() {
|
||||
Item[] items = new Item[] {
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
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)
|
||||
};
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuantities();
|
||||
// assertEquals(, app.items.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemBackstageQualityDropsToZeroAfterTheConcert() {
|
||||
System.out.println("Quality drops to 0 after the concert");
|
||||
Item[] items = new Item[]{
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 10, 2),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 9, 3),
|
||||
new Item("Backstage passes to a TAFKAL80ETC concert", 8, 7)
|
||||
};
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuantities();
|
||||
for ( Item el: items) {
|
||||
assertEquals(0, el.quality);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void itemSulfurasNotSold() {
|
||||
System.out.println("\"Sulfuras\", being a legendary item, never has to be sold");
|
||||
Item[] items = new Item[] {
|
||||
new Item("+5 Dexterity Vest", 10, 20), //
|
||||
new Item("Aged Brie", 2, 0), //
|
||||
new Item("Elixir of the Mongoose", 5, 7), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", 0, 80), //
|
||||
new Item("Sulfuras, Hand of Ragnaros", -1, 80),
|
||||
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)
|
||||
};
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuantities();
|
||||
assertEquals(2, app.items.length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user