mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 06:21:29 +00:00
Refactor method
This commit is contained in:
parent
44999deb68
commit
958f757cc4
@ -21,7 +21,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
|
|||||||
Backstage passes to a TAFKAL80ETC concert, 14, 21
|
Backstage passes to a TAFKAL80ETC concert, 14, 21
|
||||||
Backstage passes to a TAFKAL80ETC concert, 9, 50
|
Backstage passes to a TAFKAL80ETC concert, 9, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, 4, 50
|
Backstage passes to a TAFKAL80ETC concert, 4, 50
|
||||||
Conjured Mana Cake, 2, 5
|
Conjured Mana Cake, 2, 4
|
||||||
|
|
||||||
-------- day 2 --------
|
-------- day 2 --------
|
||||||
name, sellIn, quality
|
name, sellIn, quality
|
||||||
@ -33,7 +33,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
|
|||||||
Backstage passes to a TAFKAL80ETC concert, 13, 22
|
Backstage passes to a TAFKAL80ETC concert, 13, 22
|
||||||
Backstage passes to a TAFKAL80ETC concert, 8, 50
|
Backstage passes to a TAFKAL80ETC concert, 8, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, 3, 50
|
Backstage passes to a TAFKAL80ETC concert, 3, 50
|
||||||
Conjured Mana Cake, 1, 4
|
Conjured Mana Cake, 1, 2
|
||||||
|
|
||||||
-------- day 3 --------
|
-------- day 3 --------
|
||||||
name, sellIn, quality
|
name, sellIn, quality
|
||||||
@ -45,7 +45,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
|
|||||||
Backstage passes to a TAFKAL80ETC concert, 12, 23
|
Backstage passes to a TAFKAL80ETC concert, 12, 23
|
||||||
Backstage passes to a TAFKAL80ETC concert, 7, 50
|
Backstage passes to a TAFKAL80ETC concert, 7, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, 2, 50
|
Backstage passes to a TAFKAL80ETC concert, 2, 50
|
||||||
Conjured Mana Cake, 0, 3
|
Conjured Mana Cake, 0, 0
|
||||||
|
|
||||||
-------- day 4 --------
|
-------- day 4 --------
|
||||||
name, sellIn, quality
|
name, sellIn, quality
|
||||||
@ -57,7 +57,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
|
|||||||
Backstage passes to a TAFKAL80ETC concert, 11, 24
|
Backstage passes to a TAFKAL80ETC concert, 11, 24
|
||||||
Backstage passes to a TAFKAL80ETC concert, 6, 50
|
Backstage passes to a TAFKAL80ETC concert, 6, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, 1, 50
|
Backstage passes to a TAFKAL80ETC concert, 1, 50
|
||||||
Conjured Mana Cake, -1, 1
|
Conjured Mana Cake, -1, 0
|
||||||
|
|
||||||
-------- day 5 --------
|
-------- day 5 --------
|
||||||
name, sellIn, quality
|
name, sellIn, quality
|
||||||
@ -66,7 +66,7 @@ Aged Brie, -3, 8
|
|||||||
Elixir of the Mongoose, 0, 2
|
Elixir of the Mongoose, 0, 2
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 10, 25
|
Backstage passes to a TAFKAL80ETC concert, 10, 26
|
||||||
Backstage passes to a TAFKAL80ETC concert, 5, 50
|
Backstage passes to a TAFKAL80ETC concert, 5, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, 0, 50
|
Backstage passes to a TAFKAL80ETC concert, 0, 50
|
||||||
Conjured Mana Cake, -2, 0
|
Conjured Mana Cake, -2, 0
|
||||||
@ -78,7 +78,7 @@ Aged Brie, -4, 10
|
|||||||
Elixir of the Mongoose, -1, 0
|
Elixir of the Mongoose, -1, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 9, 27
|
Backstage passes to a TAFKAL80ETC concert, 9, 28
|
||||||
Backstage passes to a TAFKAL80ETC concert, 4, 50
|
Backstage passes to a TAFKAL80ETC concert, 4, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, -1, 0
|
Backstage passes to a TAFKAL80ETC concert, -1, 0
|
||||||
Conjured Mana Cake, -3, 0
|
Conjured Mana Cake, -3, 0
|
||||||
@ -90,7 +90,7 @@ Aged Brie, -5, 12
|
|||||||
Elixir of the Mongoose, -2, 0
|
Elixir of the Mongoose, -2, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 8, 29
|
Backstage passes to a TAFKAL80ETC concert, 8, 30
|
||||||
Backstage passes to a TAFKAL80ETC concert, 3, 50
|
Backstage passes to a TAFKAL80ETC concert, 3, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, -2, 0
|
Backstage passes to a TAFKAL80ETC concert, -2, 0
|
||||||
Conjured Mana Cake, -4, 0
|
Conjured Mana Cake, -4, 0
|
||||||
@ -102,7 +102,7 @@ Aged Brie, -6, 14
|
|||||||
Elixir of the Mongoose, -3, 0
|
Elixir of the Mongoose, -3, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 7, 31
|
Backstage passes to a TAFKAL80ETC concert, 7, 32
|
||||||
Backstage passes to a TAFKAL80ETC concert, 2, 50
|
Backstage passes to a TAFKAL80ETC concert, 2, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, -3, 0
|
Backstage passes to a TAFKAL80ETC concert, -3, 0
|
||||||
Conjured Mana Cake, -5, 0
|
Conjured Mana Cake, -5, 0
|
||||||
@ -114,7 +114,7 @@ Aged Brie, -7, 16
|
|||||||
Elixir of the Mongoose, -4, 0
|
Elixir of the Mongoose, -4, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 6, 33
|
Backstage passes to a TAFKAL80ETC concert, 6, 34
|
||||||
Backstage passes to a TAFKAL80ETC concert, 1, 50
|
Backstage passes to a TAFKAL80ETC concert, 1, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, -4, 0
|
Backstage passes to a TAFKAL80ETC concert, -4, 0
|
||||||
Conjured Mana Cake, -6, 0
|
Conjured Mana Cake, -6, 0
|
||||||
@ -126,7 +126,7 @@ Aged Brie, -8, 18
|
|||||||
Elixir of the Mongoose, -5, 0
|
Elixir of the Mongoose, -5, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 5, 35
|
Backstage passes to a TAFKAL80ETC concert, 5, 37
|
||||||
Backstage passes to a TAFKAL80ETC concert, 0, 50
|
Backstage passes to a TAFKAL80ETC concert, 0, 50
|
||||||
Backstage passes to a TAFKAL80ETC concert, -5, 0
|
Backstage passes to a TAFKAL80ETC concert, -5, 0
|
||||||
Conjured Mana Cake, -7, 0
|
Conjured Mana Cake, -7, 0
|
||||||
@ -138,7 +138,7 @@ Aged Brie, -9, 20
|
|||||||
Elixir of the Mongoose, -6, 0
|
Elixir of the Mongoose, -6, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 4, 38
|
Backstage passes to a TAFKAL80ETC concert, 4, 40
|
||||||
Backstage passes to a TAFKAL80ETC concert, -1, 0
|
Backstage passes to a TAFKAL80ETC concert, -1, 0
|
||||||
Backstage passes to a TAFKAL80ETC concert, -6, 0
|
Backstage passes to a TAFKAL80ETC concert, -6, 0
|
||||||
Conjured Mana Cake, -8, 0
|
Conjured Mana Cake, -8, 0
|
||||||
@ -150,7 +150,7 @@ Aged Brie, -10, 22
|
|||||||
Elixir of the Mongoose, -7, 0
|
Elixir of the Mongoose, -7, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 3, 41
|
Backstage passes to a TAFKAL80ETC concert, 3, 43
|
||||||
Backstage passes to a TAFKAL80ETC concert, -2, 0
|
Backstage passes to a TAFKAL80ETC concert, -2, 0
|
||||||
Backstage passes to a TAFKAL80ETC concert, -7, 0
|
Backstage passes to a TAFKAL80ETC concert, -7, 0
|
||||||
Conjured Mana Cake, -9, 0
|
Conjured Mana Cake, -9, 0
|
||||||
@ -162,7 +162,7 @@ Aged Brie, -11, 24
|
|||||||
Elixir of the Mongoose, -8, 0
|
Elixir of the Mongoose, -8, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 2, 44
|
Backstage passes to a TAFKAL80ETC concert, 2, 46
|
||||||
Backstage passes to a TAFKAL80ETC concert, -3, 0
|
Backstage passes to a TAFKAL80ETC concert, -3, 0
|
||||||
Backstage passes to a TAFKAL80ETC concert, -8, 0
|
Backstage passes to a TAFKAL80ETC concert, -8, 0
|
||||||
Conjured Mana Cake, -10, 0
|
Conjured Mana Cake, -10, 0
|
||||||
@ -174,7 +174,7 @@ Aged Brie, -12, 26
|
|||||||
Elixir of the Mongoose, -9, 0
|
Elixir of the Mongoose, -9, 0
|
||||||
Sulfuras, Hand of Ragnaros, 0, 80
|
Sulfuras, Hand of Ragnaros, 0, 80
|
||||||
Sulfuras, Hand of Ragnaros, -1, 80
|
Sulfuras, Hand of Ragnaros, -1, 80
|
||||||
Backstage passes to a TAFKAL80ETC concert, 1, 47
|
Backstage passes to a TAFKAL80ETC concert, 1, 49
|
||||||
Backstage passes to a TAFKAL80ETC concert, -4, 0
|
Backstage passes to a TAFKAL80ETC concert, -4, 0
|
||||||
Backstage passes to a TAFKAL80ETC concert, -9, 0
|
Backstage passes to a TAFKAL80ETC concert, -9, 0
|
||||||
Conjured Mana Cake, -11, 0
|
Conjured Mana Cake, -11, 0
|
||||||
|
|||||||
@ -1,94 +1,71 @@
|
|||||||
using System.Collections.Generic;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.Runtime.Remoting.Messaging;
|
||||||
|
|
||||||
namespace csharp
|
namespace csharp
|
||||||
{
|
{
|
||||||
public class GildedRose
|
public class GildedRose
|
||||||
{
|
{
|
||||||
|
|
||||||
private readonly IList<Item> _items;
|
private readonly IList<Item> _items;
|
||||||
|
|
||||||
public GildedRose(IList<Item> items)
|
public GildedRose(IList<Item> items)
|
||||||
=> _items = items;
|
=> _items = items;
|
||||||
|
|
||||||
|
private static int GetQualityChange(Item item)
|
||||||
|
{
|
||||||
|
var sellIn = item.SellIn;
|
||||||
|
|
||||||
|
switch (item.Name)
|
||||||
|
{
|
||||||
|
case "Sulfuras, Hand of Ragnaros":
|
||||||
|
return 0;
|
||||||
|
case "Backstage passes to a TAFKAL80ETC concert":
|
||||||
|
if (sellIn > 9)
|
||||||
|
{
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
else if (sellIn > 4)
|
||||||
|
{
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
else if (sellIn >= 0)
|
||||||
|
{
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return -item.Quality;
|
||||||
|
}
|
||||||
|
case "Aged Brie":
|
||||||
|
return sellIn < 0 ? 2 : 1;
|
||||||
|
case "Conjured Mana Cake":
|
||||||
|
return sellIn < 0 ? -4 : -2;
|
||||||
|
default:
|
||||||
|
return sellIn < 0 ? -2 : -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void UpdateQuality()
|
public void UpdateQuality()
|
||||||
{
|
{
|
||||||
foreach (var item in _items)
|
foreach (var item in _items)
|
||||||
{
|
{
|
||||||
var qualityDegradationMultiplier = item.Name == "Conjured Mana Cake" ? 2 : 1;
|
item.SellIn--;
|
||||||
|
|
||||||
if (item.Name != "Aged Brie"
|
var qualityChange = GetQualityChange(item);
|
||||||
&& item.Name != "Backstage passes to a TAFKAL80ETC concert")
|
|
||||||
{
|
|
||||||
if (item.Quality > 0)
|
|
||||||
{
|
|
||||||
if (item.Name != "Sulfuras, Hand of Ragnaros")
|
|
||||||
{
|
|
||||||
item.Quality -= qualityDegradationMultiplier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (item.Quality < 50)
|
|
||||||
{
|
|
||||||
item.Quality++;
|
|
||||||
|
|
||||||
if (item.Name == "Backstage passes to a TAFKAL80ETC concert")
|
item.Quality += qualityChange;
|
||||||
{
|
|
||||||
if (item.SellIn < 11)
|
|
||||||
{
|
|
||||||
if (item.Quality < 50)
|
|
||||||
{
|
|
||||||
item.Quality++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.SellIn < 6)
|
|
||||||
{
|
|
||||||
if (item.Quality < 50)
|
|
||||||
{
|
|
||||||
item.Quality++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.Name != "Sulfuras, Hand of Ragnaros")
|
if (item.Name != "Sulfuras, Hand of Ragnaros")
|
||||||
{
|
{
|
||||||
item.SellIn--;
|
item.Quality = Math.Min(50, item.Quality);
|
||||||
}
|
|
||||||
|
|
||||||
if (item.SellIn >= 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.Name != "Aged Brie")
|
|
||||||
{
|
|
||||||
if (item.Name != "Backstage passes to a TAFKAL80ETC concert")
|
|
||||||
{
|
|
||||||
if (item.Quality <= 0)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (item.Name != "Sulfuras, Hand of Ragnaros")
|
|
||||||
{
|
|
||||||
item.Quality -= qualityDegradationMultiplier;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
item.Quality = 0;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (item.Quality < 50)
|
item.SellIn++;
|
||||||
{
|
|
||||||
item.Quality++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
item.Quality = Math.Max(0, item.Quality);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user