Finishes separating DailyUpdate processing according to type. Still in the same method.

This commit is contained in:
Sarah Ashri 2024-03-13 14:28:27 +10:00
parent c7eafcaeec
commit 0e52fc7c4b
2 changed files with 18 additions and 22 deletions

View File

@ -31,6 +31,7 @@ public class GildedRose
!IsBackstagePassesItem(item) && !IsBackstagePassesItem(item) &&
!IsBetterWithAgeItem(item)); !IsBetterWithAgeItem(item));
private static bool IsExpired(Item item) => item.SellIn < 0;
private static void IncreaseQuality(Item item, int byValue) private static void IncreaseQuality(Item item, int byValue)
{ {
@ -47,50 +48,45 @@ public class GildedRose
{ {
if (IsLegendaryItem(item)) return; if (IsLegendaryItem(item)) return;
item.SellIn -= 1;
if (IsRegularItem(item)) if (IsRegularItem(item))
{ {
DecreaseQuality(item, 1); DecreaseQuality(item, 1);
if (IsExpired(item))
{
DecreaseQuality(item, 1);
}
} }
if (IsBetterWithAgeItem(item)) if (IsBetterWithAgeItem(item))
{ {
IncreaseQuality(item, 1); IncreaseQuality(item, 1);
if (IsExpired(item))
{
IncreaseQuality(item, 1);
}
} }
if(IsBackstagePassesItem(item)) if(IsBackstagePassesItem(item))
{ {
if (item.SellIn > 10) if (item.SellIn > 9)
{ {
IncreaseQuality(item, 1); IncreaseQuality(item, 1);
} }
else if (item.SellIn > 5) else if (item.SellIn > 4)
{ {
IncreaseQuality(item, 2); IncreaseQuality(item, 2);
} }
else else if (!IsExpired(item))
{ {
IncreaseQuality(item, 3); IncreaseQuality(item, 3);
} }
} else //Expired
item.SellIn = item.SellIn - 1;
if (item.SellIn < 0)
{
if (IsRegularItem(item))
{
DecreaseQuality(item, 1);
}
if(IsBackstagePassesItem(item))
{ {
DecreaseQuality(item, item.Quality); DecreaseQuality(item, item.Quality);
} }
}
if(IsBetterWithAgeItem(item))
{
IncreaseQuality(item, 1);
}
}
} }
} }

View File

@ -13,7 +13,7 @@ I decorated these tests with `[Ignore]` until I get to a stage in the refactorin
2. small refactorings of the UpdateQuality() method to make it more readable and separate the different (unrelated) handling of the different types.<br> 2. small refactorings of the UpdateQuality() method to make it more readable and separate the different (unrelated) handling of the different types.<br>
3. Extract Increasing/Decreasing Quality into a method.<br> 3. Extract Increasing/Decreasing Quality into a method.<br>
It feels like Quality should have been a TinyType that manages its own limits. However, since we're not allowed to change Item, I'm just extracting a method. It feels like Quality should have been a TinyType that manages its own limits. However, since we're not allowed to change Item, I'm just extracting a method.
4. Separated the processing of the different types from each other.<br>
This is the state of the code now This is the state of the code now