From 6b38601412d637a4b36c71cce7cd836466a07b4f Mon Sep 17 00:00:00 2001 From: Cory Holmes Date: Fri, 14 Feb 2025 14:05:46 -0500 Subject: [PATCH] initial commit --- csharp.xUnit/GildedRose/GildedRose.cs | 9 ++ csharp.xUnit/GildedRose/Program.cs | 1 + .../GildedRoseTests/GildedRoseTest.cs | 106 +++++++++++++++++- 3 files changed, 115 insertions(+), 1 deletion(-) diff --git a/csharp.xUnit/GildedRose/GildedRose.cs b/csharp.xUnit/GildedRose/GildedRose.cs index c08bf5f8..841a27e4 100644 --- a/csharp.xUnit/GildedRose/GildedRose.cs +++ b/csharp.xUnit/GildedRose/GildedRose.cs @@ -11,6 +11,7 @@ public class GildedRose this.Items = Items; } + public void UpdateQuality() { for (var i = 0; i < Items.Count; i++) @@ -22,7 +23,15 @@ public class GildedRose if (Items[i].Name != "Sulfuras, Hand of Ragnaros") { Items[i].Quality = Items[i].Quality - 1; + + if (Items[i].Name == "Conjured Mana Cake") + { + Items[i].Quality = Items[i].Quality - 1; + } + } + + } } else diff --git a/csharp.xUnit/GildedRose/Program.cs b/csharp.xUnit/GildedRose/Program.cs index 1c71999e..0e3f9feb 100644 --- a/csharp.xUnit/GildedRose/Program.cs +++ b/csharp.xUnit/GildedRose/Program.cs @@ -16,6 +16,7 @@ public class Program 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 = -1, Quality = 80}, + new Item { Name = "Backstage passes to a TAFKAL80ETC concert", diff --git a/csharp.xUnit/GildedRoseTests/GildedRoseTest.cs b/csharp.xUnit/GildedRoseTests/GildedRoseTest.cs index 63fd7b1b..1870984a 100644 --- a/csharp.xUnit/GildedRoseTests/GildedRoseTest.cs +++ b/csharp.xUnit/GildedRoseTests/GildedRoseTest.cs @@ -1,6 +1,7 @@ using Xunit; using System.Collections.Generic; using GildedRoseKata; +using System.Diagnostics.Metrics; namespace GildedRoseTests; @@ -12,6 +13,109 @@ public class GildedRoseTest IList Items = new List { new Item { Name = "foo", SellIn = 0, Quality = 0 } }; GildedRose app = new GildedRose(Items); app.UpdateQuality(); - Assert.Equal("fixme", Items[0].Name); + Assert.Equal("foo", Items[0].Name); } + [Fact] + public void givenSellInDateNegative_QualtiyDecreasesByTwo() + { + IList Items = new List { 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 Items = new List { 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 Items = new List { 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 Items = new List { 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 Items = new List { 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 Items = new List { 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 Items = new List { 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 Items = new List { 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 Items = new List { 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 Items = new List { new Item { Name = "Conjured Mana Cake", SellIn = 10, Quality = 10 } }; + GildedRose app = new GildedRose(Items); + app.UpdateQuality(); + Assert.Equal(8, Items[0].Quality); + } + } \ No newline at end of file