From 8f6e8e7b18840a2fa4c658145b1103c04d2a57bb Mon Sep 17 00:00:00 2001 From: Tom Clark Date: Mon, 14 Mar 2022 15:03:08 -0500 Subject: [PATCH] no message --- csharp/GildedRose.cs | 81 ++++++++- .../TestProject1/Properties/AssemblyInfo.cs | 35 ++++ csharp/TestProject1/TestProject1.csproj | 63 +++++++ csharp/TestProject1/Tests.cs | 172 ++++++++++++++++++ csharp/TestProject1/packages.config | 4 + csharp/csharp.sln | 6 + 6 files changed, 353 insertions(+), 8 deletions(-) create mode 100644 csharp/TestProject1/Properties/AssemblyInfo.cs create mode 100644 csharp/TestProject1/TestProject1.csproj create mode 100644 csharp/TestProject1/Tests.cs create mode 100644 csharp/TestProject1/packages.config diff --git a/csharp/GildedRose.cs b/csharp/GildedRose.cs index 3092424..43337b2 100644 --- a/csharp/GildedRose.cs +++ b/csharp/GildedRose.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace csharp { @@ -10,15 +11,65 @@ public GildedRose(IList Items) this.Items = Items; } + private void NoOp(Item item) + { + } + + private void DecrementSellIn(Item item) + { + item.SellIn -= 1; + } + + private void DecrementQuality(Item item) + { + item.Quality -= 1; + } + + private void DecrementQualityDouble(Item item) + { + item.Quality -= 2; + } + + private void IncrementQuality(Item item) + { + if (item.Quality < 50) + { + item.Quality = item.Quality + 1; + } + } + + private Action _getSellIn(Item item) + { + if (item.Name == "Canned Beans") + { + return NoOp; + } + + return DecrementSellIn; + } + + private Action _getQuality(Item item) + { + if (item.Name == "Aged Brie") + { + return IncrementQuality; + } + + if (item.Name == "Canned Beans") + { + return NoOp; + } + + return DecrementQuality; + } + public void UpdateQuality() { for (var i = 0; i < Items.Count; i++) { - if (Items[i].Name != "Canned Beans") - { - Items[i].SellIn = Items[i].SellIn - 1; - } - + _getSellIn(Items[i]).Invoke(Items[i]); + //_getQuality(Items[i]).Invoke(Items[i]); + if (Items[i].Name == "Aged Brie") { if (Items[i].Quality < 50) @@ -32,7 +83,14 @@ public void UpdateQuality() { if (Items[i].Name != "Canned Beans") { - Items[i].Quality = Items[i].Quality - 1; + if (Items[i].Name.ToLower().StartsWith("baked") && Items[i].Quality > 1) + { + Items[i].Quality = Items[i].Quality - 2; + } + else + { + Items[i].Quality = Items[i].Quality - 1; + } } } } @@ -52,7 +110,14 @@ public void UpdateQuality() { if (Items[i].Name != "Canned Beans") { - Items[i].Quality = Items[i].Quality - 1; + if (Items[i].Name.ToLower().StartsWith("baked") && Items[i].Quality > 1) + { + Items[i].Quality = Items[i].Quality - 2; + } + else + { + Items[i].Quality = Items[i].Quality - 1; + } } } } diff --git a/csharp/TestProject1/Properties/AssemblyInfo.cs b/csharp/TestProject1/Properties/AssemblyInfo.cs new file mode 100644 index 0000000..fb8476a --- /dev/null +++ b/csharp/TestProject1/Properties/AssemblyInfo.cs @@ -0,0 +1,35 @@ +using System.Reflection; +using System.Runtime.InteropServices; + +// General Information about an assembly is controlled through the following +// set of attributes. Change these attribute values to modify the information +// associated with an assembly. +[assembly: AssemblyTitle("TestProject1")] +[assembly: AssemblyDescription("")] +[assembly: AssemblyConfiguration("")] +[assembly: AssemblyCompany("")] +[assembly: AssemblyProduct("TestProject1")] +[assembly: AssemblyCopyright("Copyright © 2022")] +[assembly: AssemblyTrademark("")] +[assembly: AssemblyCulture("")] + +// Setting ComVisible to false makes the types in this assembly not visible +// to COM components. If you need to access a type in this assembly from +// COM, set the ComVisible attribute to true on that type. +[assembly: ComVisible(false)] + +// The following GUID is for the ID of the typelib if this project is exposed to COM +[assembly: Guid("B6C986B7-3D3E-4E65-97C6-32CBAD36CAA5")] + +// Version information for an assembly consists of the following four values: +// +// Major Version +// Minor Version +// Build Number +// Revision +// +// You can specify all the values or you can default the Build and Revision Numbers +// by using the '*' as shown below: +// [assembly: AssemblyVersion("1.0.*")] +[assembly: AssemblyVersion("1.0.0.0")] +[assembly: AssemblyFileVersion("1.0.0.0")] \ No newline at end of file diff --git a/csharp/TestProject1/TestProject1.csproj b/csharp/TestProject1/TestProject1.csproj new file mode 100644 index 0000000..c870274 --- /dev/null +++ b/csharp/TestProject1/TestProject1.csproj @@ -0,0 +1,63 @@ + + + + + Debug + AnyCPU + {B6C986B7-3D3E-4E65-97C6-32CBAD36CAA5} + {FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} + Library + Properties + TestProject1 + TestProject1 + v4.8 + 512 + + + AnyCPU + true + full + false + bin\Debug\ + DEBUG;TRACE + prompt + 4 + + + AnyCPU + pdbonly + true + bin\Release\ + TRACE + prompt + 4 + + + + + + + + ..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll + + + + + + + + + {176c0214-9136-4079-8dab-11d7420c3881} + csharp + + + + + + diff --git a/csharp/TestProject1/Tests.cs b/csharp/TestProject1/Tests.cs new file mode 100644 index 0000000..d1e9742 --- /dev/null +++ b/csharp/TestProject1/Tests.cs @@ -0,0 +1,172 @@ +using System; +using System.Collections.Generic; +using csharp; +using NUnit.Framework; + +namespace TestProject1 +{ + [TestFixture] + public class Tests + { + [Test] + public void SellInDecreases() + { + IList items = new List{ + new Item {Name = "Bananas", SellIn = 10, Quality = 20} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(9, items[0].SellIn); + } + + [Test] + public void SellInCannedBeans() + { + IList items = new List{ + new Item {Name = "Canned Beans", SellIn = 10, Quality = 20} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(10, items[0].SellIn); + } + + + + [Test] + public void QualityGeneralDecrease() + { + IList items = new List{ + new Item {Name = "General Case", SellIn = 10, Quality = 40} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(39, items[0].Quality); + } + + [Test] + public void QualityGeneralExpiredDecrease() + { + IList items = new List{ + new Item {Name = "General Case", SellIn = -1, Quality = 40} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(38, items[0].Quality); + } + + [Test] + public void QualityBrieIncrease() + { + IList items = new List{ + new Item {Name = "Aged Brie", SellIn = 10, Quality = 40} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(41, items[0].Quality); + } + + [Test] + public void QualityBrieExpiredIncrease() + { + IList items = new List{ + new Item {Name = "Aged Brie", SellIn = -1, Quality = 40} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(42, items[0].Quality); + } + + [Test] + public void QualityBrieExpiredIncrease2() + { + IList items = new List{ + new Item {Name = "Aged Brie", SellIn = -1, Quality = 49} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(50, items[0].Quality); + } + + [Test] + public void QualityBrieMax() + { + IList items = new List{ + new Item {Name = "Aged Brie", SellIn = 10, Quality = 49} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(50, items[0].Quality); + } + + [Test] + public void QualityCannedBeansStatic() + { + IList items = new List{ + new Item {Name = "Canned Beans", SellIn = 10, Quality = 40} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(40, items[0].Quality); + } + + + [Test] + public void QualityBakedDecrease() + { + IList items = new List{ + new Item {Name = "Baked Sourdough Bread", SellIn = 3, Quality = 6} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(4, items[0].Quality); + } + + [Test] + public void QualityBakedDecrease1() + { + IList items = new List{ + new Item {Name = "Baked Sourdough Bread", SellIn = 3, Quality = 1} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(0, items[0].Quality); + } + + [Test] + public void QualityBakedExpiredDecrease() + { + IList items = new List{ + new Item {Name = "Baked Sourdough Bread", SellIn = 0, Quality = 6} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(2, items[0].Quality); + } + + [Test] + public void QualityBakedExpiredDecrease1() + { + IList items = new List{ + new Item {Name = "Baked Sourdough Bread", SellIn = 0, Quality = 3} + }; + + var app = new GildedRose(items); + app.UpdateQuality(); + Assert.AreEqual(0, items[0].Quality); + } + + + } +} \ No newline at end of file diff --git a/csharp/TestProject1/packages.config b/csharp/TestProject1/packages.config new file mode 100644 index 0000000..4709b27 --- /dev/null +++ b/csharp/TestProject1/packages.config @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/csharp/csharp.sln b/csharp/csharp.sln index 62ff78a..8f3dfe2 100644 --- a/csharp/csharp.sln +++ b/csharp/csharp.sln @@ -5,6 +5,8 @@ VisualStudioVersion = 14.0.25420.1 MinimumVisualStudioVersion = 10.0.40219.1 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "csharp", "csharp.csproj", "{176C0214-9136-4079-8DAB-11D7420C3881}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TestProject1", "TestProject1\TestProject1.csproj", "{B6C986B7-3D3E-4E65-97C6-32CBAD36CAA5}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -15,6 +17,10 @@ Global {176C0214-9136-4079-8DAB-11D7420C3881}.Debug|Any CPU.Build.0 = Debug|Any CPU {176C0214-9136-4079-8DAB-11D7420C3881}.Release|Any CPU.ActiveCfg = Release|Any CPU {176C0214-9136-4079-8DAB-11D7420C3881}.Release|Any CPU.Build.0 = Release|Any CPU + {B6C986B7-3D3E-4E65-97C6-32CBAD36CAA5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B6C986B7-3D3E-4E65-97C6-32CBAD36CAA5}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B6C986B7-3D3E-4E65-97C6-32CBAD36CAA5}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B6C986B7-3D3E-4E65-97C6-32CBAD36CAA5}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE