mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
refactor: adding more test cases to increase testing coverage
This commit is contained in:
parent
a81faa5f29
commit
f691744b2b
@ -22,11 +22,8 @@ class GildedRose {
|
||||
|
||||
if (items[i].name.equals("Backstage passes to a TAFKAL80ETC concert")) {
|
||||
if (items[i].sellIn < 11 && items[i].quality < 50) {
|
||||
|
||||
items[i].quality = items[i].quality + 1;
|
||||
|
||||
}
|
||||
|
||||
if (items[i].sellIn < 6 && items[i].quality < 50) {
|
||||
items[i].quality = items[i].quality + 1;
|
||||
}
|
||||
@ -57,8 +54,4 @@ class GildedRose {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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");
|
||||
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@ -144,15 +188,15 @@ class UpdateQualityTest {
|
||||
*/
|
||||
|
||||
|
||||
@Test
|
||||
void itemConjuredQualityTwiceAsFastAsNormalItems() {
|
||||
System.out.println("\"Conjured\" items degrade in Quality twice as fast as normal items");
|
||||
Item[] items = new Item[]{
|
||||
new Item("Conjured Mana Cake", 3, 6)};
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.updateQuality();
|
||||
assertEquals(4, app.items[0].quality);
|
||||
}
|
||||
// @Test
|
||||
// void itemConjuredQualityTwiceAsFastAsNormalItems() {
|
||||
// System.out.println("\"Conjured\" items degrade in Quality twice as fast as normal items");
|
||||
// Item[] items = new Item[]{
|
||||
// new Item("Conjured Mana Cake", 3, 6)};
|
||||
// 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