mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-17 23:41:27 +00:00
Refactoring for code style consistancy
This commit is contained in:
parent
9b9b1dd5a7
commit
ed8c73bf09
@ -25,8 +25,9 @@ namespace csharpcore
|
|||||||
{
|
{
|
||||||
var lowerCaseItemName = item.Name.ToLower();
|
var lowerCaseItemName = item.Name.ToLower();
|
||||||
if (lowerCaseItemName.Contains(SULFURA_ITEM))
|
if (lowerCaseItemName.Contains(SULFURA_ITEM))
|
||||||
|
{
|
||||||
HandleSulfuraItem(item);
|
HandleSulfuraItem(item);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
item.SellIn -= 1;
|
item.SellIn -= 1;
|
||||||
@ -46,7 +47,6 @@ namespace csharpcore
|
|||||||
{
|
{
|
||||||
HandleMiscelaniousItem(item);
|
HandleMiscelaniousItem(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -59,54 +59,70 @@ namespace csharpcore
|
|||||||
private void HandleAgedBrieItem(Item item)
|
private void HandleAgedBrieItem(Item item)
|
||||||
{
|
{
|
||||||
if (item.SellIn > 0)
|
if (item.SellIn > 0)
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, 1);
|
UpdateItemQualityValue(item, 1);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, 2); // Is it correct ? This is to reflect old code but seems to not be in the spec
|
UpdateItemQualityValue(item, 2); // Is it correct ? This is to reflect old code but seems to not be in the spec
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleBackstagePassItem(Item item)
|
private void HandleBackstagePassItem(Item item)
|
||||||
{
|
{
|
||||||
if (item.SellIn >= 10)
|
if (item.SellIn >= 10)
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, 1);
|
UpdateItemQualityValue(item, 1);
|
||||||
|
}
|
||||||
else if (item.SellIn >= 5)
|
else if (item.SellIn >= 5)
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, 2);
|
UpdateItemQualityValue(item, 2);
|
||||||
|
}
|
||||||
else if (item.SellIn > 0)
|
else if (item.SellIn > 0)
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, 3);
|
UpdateItemQualityValue(item, 3);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
item.Quality = MIN_QUALITY;
|
item.Quality = MIN_QUALITY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleConjuredItem(Item item)
|
private void HandleConjuredItem(Item item)
|
||||||
{
|
{
|
||||||
if (item.SellIn > 0)
|
if (item.SellIn > 0)
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, -2);
|
UpdateItemQualityValue(item, -2);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, -4);
|
UpdateItemQualityValue(item, -4);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void HandleMiscelaniousItem(Item item)
|
private void HandleMiscelaniousItem(Item item)
|
||||||
{
|
{
|
||||||
if (item.SellIn > 0)
|
if (item.SellIn > 0)
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, -1);
|
UpdateItemQualityValue(item, -1);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
UpdateItemQualityValue(item, -2);
|
UpdateItemQualityValue(item, -2);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateItemQualityValue(Item item, int qualityStep)
|
private void UpdateItemQualityValue(Item item, int qualityStep)
|
||||||
{
|
{
|
||||||
item.Quality += qualityStep;
|
item.Quality += qualityStep;
|
||||||
if (item.Quality < MIN_QUALITY)
|
if (item.Quality < MIN_QUALITY)
|
||||||
|
{
|
||||||
item.Quality = MIN_QUALITY;
|
item.Quality = MIN_QUALITY;
|
||||||
|
}
|
||||||
if (item.Quality > MAX_QUALITY)
|
else if (item.Quality > MAX_QUALITY)
|
||||||
|
{
|
||||||
item.Quality = MAX_QUALITY;
|
item.Quality = MAX_QUALITY;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,13 +60,7 @@ namespace csharpcore
|
|||||||
[InlineData(5, 7, 10)]
|
[InlineData(5, 7, 10)]
|
||||||
public void UpdateQuality_BackStagePass_QualityIncreases(int beforeSellIn, int beforeQuality, int afterQuality)
|
public void UpdateQuality_BackStagePass_QualityIncreases(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
{
|
{
|
||||||
IList<Item> items = new List<Item> {
|
IList<Item> items = new List<Item> { new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = beforeSellIn, Quality = beforeQuality } };
|
||||||
new Item {
|
|
||||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
|
||||||
SellIn = beforeSellIn,
|
|
||||||
Quality = beforeQuality
|
|
||||||
}
|
|
||||||
};
|
|
||||||
GildedRose app = new GildedRose(items);
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
app.UpdateQuality();
|
app.UpdateQuality();
|
||||||
@ -80,13 +74,7 @@ namespace csharpcore
|
|||||||
[InlineData(0, 50, 0)]
|
[InlineData(0, 50, 0)]
|
||||||
public void UpdateQuality_BackStagePassAfterConcert_QualityZeroed(int beforeSellIn, int beforeQuality, int afterQuality)
|
public void UpdateQuality_BackStagePassAfterConcert_QualityZeroed(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
{
|
{
|
||||||
IList<Item> items = new List<Item> {
|
IList<Item> items = new List<Item> { new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = beforeSellIn, Quality = beforeQuality } };
|
||||||
new Item {
|
|
||||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
|
||||||
SellIn = beforeSellIn,
|
|
||||||
Quality = beforeQuality
|
|
||||||
}
|
|
||||||
};
|
|
||||||
GildedRose app = new GildedRose(items);
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
app.UpdateQuality();
|
app.UpdateQuality();
|
||||||
@ -101,13 +89,7 @@ namespace csharpcore
|
|||||||
[InlineData(5, 50, 50)]
|
[InlineData(5, 50, 50)]
|
||||||
public void UpdateQuality_BackStagePassMaxQuality_QualityToppedAtFifty(int beforeSellIn, int beforeQuality, int afterQuality)
|
public void UpdateQuality_BackStagePassMaxQuality_QualityToppedAtFifty(int beforeSellIn, int beforeQuality, int afterQuality)
|
||||||
{
|
{
|
||||||
IList<Item> items = new List<Item> {
|
IList<Item> items = new List<Item> { new Item { Name = "Backstage passes to a TAFKAL80ETC concert", SellIn = beforeSellIn, Quality = beforeQuality } };
|
||||||
new Item {
|
|
||||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
|
||||||
SellIn = beforeSellIn,
|
|
||||||
Quality = beforeQuality
|
|
||||||
}
|
|
||||||
};
|
|
||||||
GildedRose app = new GildedRose(items);
|
GildedRose app = new GildedRose(items);
|
||||||
|
|
||||||
app.UpdateQuality();
|
app.UpdateQuality();
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user