mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 06:21:29 +00:00
* in tests: - renamed tests to use the different item types - Added more test cases to support the fixed functionality of better types' recognition. * reran the 30 days texttest to verify the changes until now
105 lines
2.6 KiB
C#
105 lines
2.6 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace GildedRoseKata;
|
|
|
|
public class GildedRose
|
|
{
|
|
private readonly IList<Item> _items;
|
|
const int MinQuality = 0;
|
|
const int MaxQuality = 50;
|
|
|
|
public GildedRose(IList<Item> items)
|
|
{
|
|
_items = items;
|
|
}
|
|
|
|
public void UpdateQuality()
|
|
{
|
|
foreach (var item in _items)
|
|
{
|
|
DailyItemUpdate(item);
|
|
}
|
|
}
|
|
|
|
private static bool IsLegendaryItem(Item item) => item.Name.ToLower().Contains("sulfuras");
|
|
|
|
private static bool IsBackstagePassesItem(Item item) => item.Name.ToLower().Contains("backstage passes");
|
|
|
|
private static bool IsBetterWithAgeItem(Item item) => item.Name.ToLower().Equals("aged brie");
|
|
|
|
|
|
|
|
|
|
private void DailyItemUpdate(Item item)
|
|
{
|
|
if (!IsBetterWithAgeItem(item) && !IsBackstagePassesItem(item))
|
|
{
|
|
if (item.Quality > MinQuality)
|
|
{
|
|
if (!IsLegendaryItem(item))
|
|
{
|
|
item.Quality = item.Quality - 1;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (item.Quality < MaxQuality)
|
|
{
|
|
item.Quality = item.Quality + 1;
|
|
|
|
if (IsBackstagePassesItem(item))
|
|
{
|
|
if (item.SellIn < 11)
|
|
{
|
|
if (item.Quality < MaxQuality)
|
|
{
|
|
item.Quality = item.Quality + 1;
|
|
}
|
|
}
|
|
|
|
if (item.SellIn < 6)
|
|
{
|
|
if (item.Quality < MaxQuality)
|
|
{
|
|
item.Quality = item.Quality + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
if (!IsLegendaryItem(item))
|
|
{
|
|
item.SellIn = item.SellIn - 1;
|
|
}
|
|
|
|
if (item.SellIn < 0)
|
|
{
|
|
if (!IsBetterWithAgeItem(item))
|
|
{
|
|
if (!IsBackstagePassesItem(item))
|
|
{
|
|
if (item.Quality > MinQuality)
|
|
{
|
|
if (!IsLegendaryItem(item))
|
|
{
|
|
item.Quality = item.Quality - 1;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
item.Quality = item.Quality - item.Quality;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (item.Quality < MaxQuality)
|
|
{
|
|
item.Quality = item.Quality + 1;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |