mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
commit
ee8917dc92
@ -1,86 +1,86 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GildedRoseKata
|
||||
namespace GildedRoseKata;
|
||||
|
||||
public class GildedRose
|
||||
{
|
||||
public class GildedRose
|
||||
private readonly IList<Item> _items;
|
||||
|
||||
public GildedRose(IList<Item> items)
|
||||
{
|
||||
IList<Item> Items;
|
||||
public GildedRose(IList<Item> Items)
|
||||
{
|
||||
this.Items = Items;
|
||||
_items = items;
|
||||
}
|
||||
|
||||
public void UpdateQuality()
|
||||
{
|
||||
for (var i = 0; i < Items.Count; i++)
|
||||
for (var i = 0; i < _items.Count; i++)
|
||||
{
|
||||
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
if (_items[i].Name != "Aged Brie" && _items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
{
|
||||
if (Items[i].Quality > 0)
|
||||
if (_items[i].Quality > 0)
|
||||
{
|
||||
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - 1;
|
||||
_items[i].Quality = _items[i].Quality - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Items[i].Quality < 50)
|
||||
if (_items[i].Quality < 50)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
_items[i].Quality = _items[i].Quality + 1;
|
||||
|
||||
if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
|
||||
if (_items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
|
||||
{
|
||||
if (Items[i].SellIn < 11)
|
||||
if (_items[i].SellIn < 11)
|
||||
{
|
||||
if (Items[i].Quality < 50)
|
||||
if (_items[i].Quality < 50)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
_items[i].Quality = _items[i].Quality + 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (Items[i].SellIn < 6)
|
||||
if (_items[i].SellIn < 6)
|
||||
{
|
||||
if (Items[i].Quality < 50)
|
||||
if (_items[i].Quality < 50)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
_items[i].Quality = _items[i].Quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
Items[i].SellIn = Items[i].SellIn - 1;
|
||||
_items[i].SellIn = _items[i].SellIn - 1;
|
||||
}
|
||||
|
||||
if (Items[i].SellIn < 0)
|
||||
if (_items[i].SellIn < 0)
|
||||
{
|
||||
if (Items[i].Name != "Aged Brie")
|
||||
if (_items[i].Name != "Aged Brie")
|
||||
{
|
||||
if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
if (_items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
|
||||
{
|
||||
if (Items[i].Quality > 0)
|
||||
if (_items[i].Quality > 0)
|
||||
{
|
||||
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
if (_items[i].Name != "Sulfuras, Hand of Ragnaros")
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - 1;
|
||||
_items[i].Quality = _items[i].Quality - 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality - Items[i].Quality;
|
||||
_items[i].Quality = _items[i].Quality - _items[i].Quality;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Items[i].Quality < 50)
|
||||
if (_items[i].Quality < 50)
|
||||
{
|
||||
Items[i].Quality = Items[i].Quality + 1;
|
||||
}
|
||||
_items[i].Quality = _items[i].Quality + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,9 +1,8 @@
|
||||
namespace GildedRoseKata
|
||||
namespace GildedRoseKata;
|
||||
|
||||
public class Item
|
||||
{
|
||||
public class Item
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public int SellIn { get; set; }
|
||||
public int Quality { get; set; }
|
||||
}
|
||||
}
|
||||
@ -3,27 +3,24 @@ using System.IO;
|
||||
using System.Text;
|
||||
using ApprovalTests;
|
||||
using ApprovalTests.Reporters;
|
||||
using GildedRoseTests;
|
||||
using NUnit.Framework;
|
||||
|
||||
namespace csharp
|
||||
namespace GildedRoseTests;
|
||||
|
||||
[UseReporter(typeof(DiffReporter))]
|
||||
[TestFixture]
|
||||
public class ApprovalTest
|
||||
{
|
||||
[UseReporter(typeof(DiffReporter))]
|
||||
[TestFixture]
|
||||
public class ApprovalTest
|
||||
{
|
||||
[Test]
|
||||
public void ThirtyDays()
|
||||
{
|
||||
StringBuilder fakeOutput = new StringBuilder();
|
||||
Console.SetOut(new StringWriter(fakeOutput));
|
||||
Console.SetIn(new StringReader($"a{Environment.NewLine}"));
|
||||
|
||||
StringBuilder fakeoutput = new StringBuilder();
|
||||
Console.SetOut(new StringWriter(fakeoutput));
|
||||
Console.SetIn(new StringReader("a\n"));
|
||||
|
||||
TexttestFixture.Main(new string[] { });
|
||||
var output = fakeoutput.ToString();
|
||||
TextTestFixture.Main(new string[] { });
|
||||
var output = fakeOutput.ToString();
|
||||
|
||||
Approvals.Verify(output);
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -2,17 +2,16 @@
|
||||
using System.Collections.Generic;
|
||||
using GildedRoseKata;
|
||||
|
||||
namespace GildedRoseTests
|
||||
namespace GildedRoseTests;
|
||||
|
||||
public class GildedRoseTest
|
||||
{
|
||||
public class GildedRoseTest
|
||||
{
|
||||
[Fact]
|
||||
public void foo()
|
||||
public void Foo()
|
||||
{
|
||||
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
|
||||
GildedRose app = new GildedRose(Items);
|
||||
IList<Item> items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } };
|
||||
GildedRose app = new GildedRose(items);
|
||||
app.UpdateQuality();
|
||||
Assert.Equal("fixme", Items[0].Name);
|
||||
}
|
||||
Assert.Equal("fixme", items[0].Name);
|
||||
}
|
||||
}
|
||||
@ -3,7 +3,7 @@
|
||||
<PropertyGroup>
|
||||
<OutputType>Exe</OutputType>
|
||||
<TargetFramework>net7.0</TargetFramework>
|
||||
<StartupObject>GildedRoseTests.TexttestFixture</StartupObject>
|
||||
<StartupObject>GildedRoseTests.TextTestFixture</StartupObject>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
|
||||
61
csharpcore/GildedRoseTests/TextTestFixture.cs
Normal file
61
csharpcore/GildedRoseTests/TextTestFixture.cs
Normal file
@ -0,0 +1,61 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GildedRoseKata;
|
||||
|
||||
namespace GildedRoseTests;
|
||||
|
||||
public static class TextTestFixture
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("OMGHAI!");
|
||||
|
||||
IList<Item> items = new List<Item>{
|
||||
new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20},
|
||||
new Item {Name = "Aged Brie", SellIn = 2, Quality = 0},
|
||||
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",
|
||||
SellIn = 15,
|
||||
Quality = 20
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 10,
|
||||
Quality = 49
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 5,
|
||||
Quality = 49
|
||||
},
|
||||
// this conjured item does not work properly yet
|
||||
new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
|
||||
};
|
||||
|
||||
var app = new GildedRose(items);
|
||||
|
||||
int days = 31;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
days = int.Parse(args[0]) + 1;
|
||||
}
|
||||
|
||||
for (var i = 0; i < days; i++)
|
||||
{
|
||||
Console.WriteLine("-------- day " + i + " --------");
|
||||
Console.WriteLine("name, sellIn, quality");
|
||||
for (var j = 0; j < items.Count; j++)
|
||||
{
|
||||
Console.WriteLine(items[j].Name + ", " + items[j].SellIn + ", " + items[j].Quality);
|
||||
}
|
||||
Console.WriteLine("");
|
||||
app.UpdateQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -1,64 +0,0 @@
|
||||
|
||||
using GildedRoseKata;
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GildedRoseTests
|
||||
{
|
||||
public static class TexttestFixture
|
||||
{
|
||||
public static void Main(string[] args)
|
||||
{
|
||||
Console.WriteLine("OMGHAI!");
|
||||
|
||||
IList<Item> Items = new List<Item>{
|
||||
new Item {Name = "+5 Dexterity Vest", SellIn = 10, Quality = 20},
|
||||
new Item {Name = "Aged Brie", SellIn = 2, Quality = 0},
|
||||
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",
|
||||
SellIn = 15,
|
||||
Quality = 20
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 10,
|
||||
Quality = 49
|
||||
},
|
||||
new Item
|
||||
{
|
||||
Name = "Backstage passes to a TAFKAL80ETC concert",
|
||||
SellIn = 5,
|
||||
Quality = 49
|
||||
},
|
||||
// this conjured item does not work properly yet
|
||||
new Item {Name = "Conjured Mana Cake", SellIn = 3, Quality = 6}
|
||||
};
|
||||
|
||||
var app = new GildedRose(Items);
|
||||
|
||||
int days = 31;
|
||||
if (args.Length > 0)
|
||||
{
|
||||
days = int.Parse(args[0]) + 1;
|
||||
}
|
||||
|
||||
for (var i = 0; i < days; i++)
|
||||
{
|
||||
Console.WriteLine("-------- day " + i + " --------");
|
||||
Console.WriteLine("name, sellIn, quality");
|
||||
for (var j = 0; j < Items.Count; j++)
|
||||
{
|
||||
System.Console.WriteLine(Items[j].Name + ", " + Items[j].SellIn + ", " + Items[j].Quality);
|
||||
}
|
||||
Console.WriteLine("");
|
||||
app.UpdateQuality();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user