mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-10 12:11:20 +00:00
initial commit
This commit is contained in:
parent
afd4627ee1
commit
6b38601412
@ -11,6 +11,7 @@ public class GildedRose
|
|||||||
this.Items = Items;
|
this.Items = Items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void UpdateQuality()
|
public void UpdateQuality()
|
||||||
{
|
{
|
||||||
for (var i = 0; i < Items.Count; i++)
|
for (var i = 0; i < Items.Count; i++)
|
||||||
@ -22,7 +23,15 @@ public class GildedRose
|
|||||||
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||||
{
|
{
|
||||||
Items[i].Quality = Items[i].Quality - 1;
|
Items[i].Quality = Items[i].Quality - 1;
|
||||||
|
|
||||||
|
if (Items[i].Name == "Conjured Mana Cake")
|
||||||
|
{
|
||||||
|
Items[i].Quality = Items[i].Quality - 1;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -16,6 +16,7 @@ public class Program
|
|||||||
new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7},
|
new Item {Name = "Elixir of the Mongoose", SellIn = 5, Quality = 7},
|
||||||
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80},
|
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = 0, Quality = 80},
|
||||||
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = -1, Quality = 80},
|
new Item {Name = "Sulfuras, Hand of Ragnaros", SellIn = -1, Quality = 80},
|
||||||
|
|
||||||
new Item
|
new Item
|
||||||
{
|
{
|
||||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||||
|
|||||||
@ -1,6 +1,7 @@
|
|||||||
using Xunit;
|
using Xunit;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using GildedRoseKata;
|
using GildedRoseKata;
|
||||||
|
using System.Diagnostics.Metrics;
|
||||||
|
|
||||||
namespace GildedRoseTests;
|
namespace GildedRoseTests;
|
||||||
|
|
||||||
@ -12,6 +13,109 @@ public class GildedRoseTest
|
|||||||
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
|
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
|
||||||
GildedRose app = new GildedRose(Items);
|
GildedRose app = new GildedRose(Items);
|
||||||
app.UpdateQuality();
|
app.UpdateQuality();
|
||||||
Assert.Equal("fixme", Items[0].Name);
|
Assert.Equal("foo", Items[0].Name);
|
||||||
}
|
}
|
||||||
|
[Fact]
|
||||||
|
public void givenSellInDateNegative_QualtiyDecreasesByTwo()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 2 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(0, Items[0].Quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void givenUpdate_QualityNeverLessThanZero ()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 1 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(0, Items[0].Quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Aged Brie" actually increases in Quality the older it get
|
||||||
|
[Fact]
|
||||||
|
public void givenAgedBrie_QualityIncreases()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "Aged Brie", SellIn = 1, Quality = 1 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(2, Items[0].Quality);
|
||||||
|
}
|
||||||
|
//The Quality of an item is never more than 50
|
||||||
|
[Fact]
|
||||||
|
public void givenQualityUpdate_QualityNotGreaterThanFifty ()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "Aged Brie", SellIn = 0, Quality = 50 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(50, Items[0].Quality);
|
||||||
|
}
|
||||||
|
[Fact] // need to update this, quality needs to cap at 50
|
||||||
|
public void givenAgedBrieAndSellInGreaterThanZero_QualityIncreasesByOne()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "Aged Brie", SellIn = 10, Quality = 49 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(50, Items[0].Quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
//"Sulfuras", being a legendary item, never has to be sold or decreases in Quality
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void givenSulfuras_NeverSoldOrDecreasesInQuality ()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "Sulfuras, Hand of Ragnaros", SellIn = 10, Quality = 80 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(80, Items[0].Quality);
|
||||||
|
Assert.Equal(10, Items[0].SellIn);
|
||||||
|
}
|
||||||
|
|
||||||
|
// "Backstage passes", like aged brie, increases in Quality as its SellIn value approaches;
|
||||||
|
// Quality increases by 2 when there are 10 days or less
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void givenBackstagePasses_QualityIncreaseByTwoWhenTenDaysOrLess ()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 6, Quality = 6 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(8, Items[0].Quality);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// and by 3 when there are 5 days or less but
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void givenBackstagePasses_QualityIncreaseByThreeWhenFiveDaysOrLess()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 4, Quality = 6 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(9, Items[0].Quality);
|
||||||
|
|
||||||
|
}
|
||||||
|
//Quality drops to 0 after the concert
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void givenBackstagePasses_QualityIsZeroAfterConcert()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = 0, Quality = 6 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(0, Items[0].Quality);
|
||||||
|
}
|
||||||
|
|
||||||
|
///"Conjured" items degrade in Quality twice as fast as normal items
|
||||||
|
|
||||||
|
[Fact]
|
||||||
|
public void givenConjuredItem_QualityDegradesTwiceAsFastAsNormal ()
|
||||||
|
{
|
||||||
|
IList<Item> Items = new List<Item> { new Item { Name = "Conjured Mana Cake", SellIn = 10, Quality = 10 } };
|
||||||
|
GildedRose app = new GildedRose(Items);
|
||||||
|
app.UpdateQuality();
|
||||||
|
Assert.Equal(8, Items[0].Quality);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
Loading…
Reference in New Issue
Block a user