Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 73 additions & 8 deletions csharp/GildedRose.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Collections.Generic;
using System;
using System.Collections.Generic;

namespace csharp
{
Expand All @@ -10,15 +11,65 @@ public GildedRose(IList<Item> 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<Item> _getSellIn(Item item)
{
if (item.Name == "Canned Beans")
{
return NoOp;
}

return DecrementSellIn;
}

private Action<Item> _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)
Expand All @@ -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;
}
}
}
}
Expand All @@ -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;
}
}
}
}
Expand Down
35 changes: 35 additions & 0 deletions csharp/TestProject1/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -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")]
63 changes: 63 additions & 0 deletions csharp/TestProject1/TestProject1.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{B6C986B7-3D3E-4E65-97C6-32CBAD36CAA5}</ProjectGuid>
<ProjectTypeGuids>{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestProject1</RootNamespace>
<AssemblyName>TestProject1</AssemblyName>
<TargetFrameworkVersion>v4.8</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Xml" />
<Reference Include="nunit.framework, Version=3.5.0.0, Culture=neutral, PublicKeyToken=2638cd05610744eb">
<HintPath>..\packages\NUnit.3.5.0\lib\net45\nunit.framework.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\csharp.csproj">
<Project>{176c0214-9136-4079-8dab-11d7420c3881}</Project>
<Name>csharp</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->

</Project>
172 changes: 172 additions & 0 deletions csharp/TestProject1/Tests.cs
Original file line number Diff line number Diff line change
@@ -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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
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<Item> items = new List<Item>{
new Item {Name = "Baked Sourdough Bread", SellIn = 0, Quality = 3}
};

var app = new GildedRose(items);
app.UpdateQuality();
Assert.AreEqual(0, items[0].Quality);
}


}
}
4 changes: 4 additions & 0 deletions csharp/TestProject1/packages.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="NUnit" version="3.5.0" targetFramework="net45" />
</packages>
Loading