This commit is contained in:
radekSQ 2018-05-09 20:02:24 +00:00 committed by GitHub
commit 411a25aa4b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 313 additions and 87 deletions

View File

@ -21,7 +21,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 14, 21 Backstage passes to a TAFKAL80ETC concert, 14, 21
Backstage passes to a TAFKAL80ETC concert, 9, 50 Backstage passes to a TAFKAL80ETC concert, 9, 50
Backstage passes to a TAFKAL80ETC concert, 4, 50 Backstage passes to a TAFKAL80ETC concert, 4, 50
Conjured Mana Cake, 2, 5 Conjured Mana Cake, 2, 4
-------- day 2 -------- -------- day 2 --------
name, sellIn, quality name, sellIn, quality
@ -33,7 +33,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 13, 22 Backstage passes to a TAFKAL80ETC concert, 13, 22
Backstage passes to a TAFKAL80ETC concert, 8, 50 Backstage passes to a TAFKAL80ETC concert, 8, 50
Backstage passes to a TAFKAL80ETC concert, 3, 50 Backstage passes to a TAFKAL80ETC concert, 3, 50
Conjured Mana Cake, 1, 4 Conjured Mana Cake, 1, 2
-------- day 3 -------- -------- day 3 --------
name, sellIn, quality name, sellIn, quality
@ -45,7 +45,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 12, 23 Backstage passes to a TAFKAL80ETC concert, 12, 23
Backstage passes to a TAFKAL80ETC concert, 7, 50 Backstage passes to a TAFKAL80ETC concert, 7, 50
Backstage passes to a TAFKAL80ETC concert, 2, 50 Backstage passes to a TAFKAL80ETC concert, 2, 50
Conjured Mana Cake, 0, 3 Conjured Mana Cake, 0, 0
-------- day 4 -------- -------- day 4 --------
name, sellIn, quality name, sellIn, quality
@ -57,7 +57,7 @@ Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 11, 24 Backstage passes to a TAFKAL80ETC concert, 11, 24
Backstage passes to a TAFKAL80ETC concert, 6, 50 Backstage passes to a TAFKAL80ETC concert, 6, 50
Backstage passes to a TAFKAL80ETC concert, 1, 50 Backstage passes to a TAFKAL80ETC concert, 1, 50
Conjured Mana Cake, -1, 1 Conjured Mana Cake, -1, 0
-------- day 5 -------- -------- day 5 --------
name, sellIn, quality name, sellIn, quality
@ -66,7 +66,7 @@ Aged Brie, -3, 8
Elixir of the Mongoose, 0, 2 Elixir of the Mongoose, 0, 2
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 10, 25 Backstage passes to a TAFKAL80ETC concert, 10, 26
Backstage passes to a TAFKAL80ETC concert, 5, 50 Backstage passes to a TAFKAL80ETC concert, 5, 50
Backstage passes to a TAFKAL80ETC concert, 0, 50 Backstage passes to a TAFKAL80ETC concert, 0, 50
Conjured Mana Cake, -2, 0 Conjured Mana Cake, -2, 0
@ -78,7 +78,7 @@ Aged Brie, -4, 10
Elixir of the Mongoose, -1, 0 Elixir of the Mongoose, -1, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 9, 27 Backstage passes to a TAFKAL80ETC concert, 9, 28
Backstage passes to a TAFKAL80ETC concert, 4, 50 Backstage passes to a TAFKAL80ETC concert, 4, 50
Backstage passes to a TAFKAL80ETC concert, -1, 0 Backstage passes to a TAFKAL80ETC concert, -1, 0
Conjured Mana Cake, -3, 0 Conjured Mana Cake, -3, 0
@ -90,7 +90,7 @@ Aged Brie, -5, 12
Elixir of the Mongoose, -2, 0 Elixir of the Mongoose, -2, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 8, 29 Backstage passes to a TAFKAL80ETC concert, 8, 30
Backstage passes to a TAFKAL80ETC concert, 3, 50 Backstage passes to a TAFKAL80ETC concert, 3, 50
Backstage passes to a TAFKAL80ETC concert, -2, 0 Backstage passes to a TAFKAL80ETC concert, -2, 0
Conjured Mana Cake, -4, 0 Conjured Mana Cake, -4, 0
@ -102,7 +102,7 @@ Aged Brie, -6, 14
Elixir of the Mongoose, -3, 0 Elixir of the Mongoose, -3, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 7, 31 Backstage passes to a TAFKAL80ETC concert, 7, 32
Backstage passes to a TAFKAL80ETC concert, 2, 50 Backstage passes to a TAFKAL80ETC concert, 2, 50
Backstage passes to a TAFKAL80ETC concert, -3, 0 Backstage passes to a TAFKAL80ETC concert, -3, 0
Conjured Mana Cake, -5, 0 Conjured Mana Cake, -5, 0
@ -114,7 +114,7 @@ Aged Brie, -7, 16
Elixir of the Mongoose, -4, 0 Elixir of the Mongoose, -4, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 6, 33 Backstage passes to a TAFKAL80ETC concert, 6, 34
Backstage passes to a TAFKAL80ETC concert, 1, 50 Backstage passes to a TAFKAL80ETC concert, 1, 50
Backstage passes to a TAFKAL80ETC concert, -4, 0 Backstage passes to a TAFKAL80ETC concert, -4, 0
Conjured Mana Cake, -6, 0 Conjured Mana Cake, -6, 0
@ -126,7 +126,7 @@ Aged Brie, -8, 18
Elixir of the Mongoose, -5, 0 Elixir of the Mongoose, -5, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 5, 35 Backstage passes to a TAFKAL80ETC concert, 5, 37
Backstage passes to a TAFKAL80ETC concert, 0, 50 Backstage passes to a TAFKAL80ETC concert, 0, 50
Backstage passes to a TAFKAL80ETC concert, -5, 0 Backstage passes to a TAFKAL80ETC concert, -5, 0
Conjured Mana Cake, -7, 0 Conjured Mana Cake, -7, 0
@ -138,7 +138,7 @@ Aged Brie, -9, 20
Elixir of the Mongoose, -6, 0 Elixir of the Mongoose, -6, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 4, 38 Backstage passes to a TAFKAL80ETC concert, 4, 40
Backstage passes to a TAFKAL80ETC concert, -1, 0 Backstage passes to a TAFKAL80ETC concert, -1, 0
Backstage passes to a TAFKAL80ETC concert, -6, 0 Backstage passes to a TAFKAL80ETC concert, -6, 0
Conjured Mana Cake, -8, 0 Conjured Mana Cake, -8, 0
@ -150,7 +150,7 @@ Aged Brie, -10, 22
Elixir of the Mongoose, -7, 0 Elixir of the Mongoose, -7, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 3, 41 Backstage passes to a TAFKAL80ETC concert, 3, 43
Backstage passes to a TAFKAL80ETC concert, -2, 0 Backstage passes to a TAFKAL80ETC concert, -2, 0
Backstage passes to a TAFKAL80ETC concert, -7, 0 Backstage passes to a TAFKAL80ETC concert, -7, 0
Conjured Mana Cake, -9, 0 Conjured Mana Cake, -9, 0
@ -162,7 +162,7 @@ Aged Brie, -11, 24
Elixir of the Mongoose, -8, 0 Elixir of the Mongoose, -8, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 2, 44 Backstage passes to a TAFKAL80ETC concert, 2, 46
Backstage passes to a TAFKAL80ETC concert, -3, 0 Backstage passes to a TAFKAL80ETC concert, -3, 0
Backstage passes to a TAFKAL80ETC concert, -8, 0 Backstage passes to a TAFKAL80ETC concert, -8, 0
Conjured Mana Cake, -10, 0 Conjured Mana Cake, -10, 0
@ -174,7 +174,7 @@ Aged Brie, -12, 26
Elixir of the Mongoose, -9, 0 Elixir of the Mongoose, -9, 0
Sulfuras, Hand of Ragnaros, 0, 80 Sulfuras, Hand of Ragnaros, 0, 80
Sulfuras, Hand of Ragnaros, -1, 80 Sulfuras, Hand of Ragnaros, -1, 80
Backstage passes to a TAFKAL80ETC concert, 1, 47 Backstage passes to a TAFKAL80ETC concert, 1, 49
Backstage passes to a TAFKAL80ETC concert, -4, 0 Backstage passes to a TAFKAL80ETC concert, -4, 0
Backstage passes to a TAFKAL80ETC concert, -9, 0 Backstage passes to a TAFKAL80ETC concert, -9, 0
Conjured Mana Cake, -11, 0 Conjured Mana Cake, -11, 0

View File

@ -1,88 +1,71 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.Runtime.Remoting.Messaging;
namespace csharp namespace csharp
{ {
public class GildedRose public class GildedRose
{ {
IList<Item> Items;
public GildedRose(IList<Item> Items) private readonly IList<Item> _items;
public GildedRose(IList<Item> items)
=> _items = items;
private static int GetQualityChange(Item item)
{ {
this.Items = Items; var sellIn = item.SellIn;
switch (item.Name)
{
case "Sulfuras, Hand of Ragnaros":
return 0;
case "Backstage passes to a TAFKAL80ETC concert":
if (sellIn > 9)
{
return 1;
}
else if (sellIn > 4)
{
return 2;
}
else if (sellIn >= 0)
{
return 3;
}
else
{
return -item.Quality;
}
case "Aged Brie":
return sellIn < 0 ? 2 : 1;
case "Conjured Mana Cake":
return sellIn < 0 ? -4 : -2;
default:
return sellIn < 0 ? -2 : -1;
}
} }
public void UpdateQuality() public void UpdateQuality()
{ {
for (var i = 0; i < Items.Count; i++) foreach (var item in _items)
{ {
if (Items[i].Name != "Aged Brie" && Items[i].Name != "Backstage passes to a TAFKAL80ETC concert") item.SellIn--;
var qualityChange = GetQualityChange(item);
item.Quality += qualityChange;
if (item.Name != "Sulfuras, Hand of Ragnaros")
{ {
if (Items[i].Quality > 0) item.Quality = Math.Min(50, item.Quality);
{
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{
Items[i].Quality = Items[i].Quality - 1;
}
}
} }
else else
{ {
if (Items[i].Quality < 50) item.SellIn++;
{
Items[i].Quality = Items[i].Quality + 1;
if (Items[i].Name == "Backstage passes to a TAFKAL80ETC concert")
{
if (Items[i].SellIn < 11)
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
}
} }
if (Items[i].SellIn < 6) item.Quality = Math.Max(0, item.Quality);
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
}
}
}
}
}
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{
Items[i].SellIn = Items[i].SellIn - 1;
}
if (Items[i].SellIn < 0)
{
if (Items[i].Name != "Aged Brie")
{
if (Items[i].Name != "Backstage passes to a TAFKAL80ETC concert")
{
if (Items[i].Quality > 0)
{
if (Items[i].Name != "Sulfuras, Hand of Ragnaros")
{
Items[i].Quality = Items[i].Quality - 1;
}
}
}
else
{
Items[i].Quality = Items[i].Quality - Items[i].Quality;
}
}
else
{
if (Items[i].Quality < 50)
{
Items[i].Quality = Items[i].Quality + 1;
}
}
}
} }
} }
} }

View File

@ -7,12 +7,255 @@ namespace csharp
public class GildedRoseTest public class GildedRoseTest
{ {
[Test] [Test]
public void foo() public void UpdateQuality_LowersItemQualityBy1()
{ {
IList<Item> Items = new List<Item> { new Item { Name = "foo", SellIn = 0, Quality = 0 } }; var item = new Item
GildedRose app = new GildedRose(Items); {
app.UpdateQuality(); Name = "test",
Assert.AreEqual("fixme", Items[0].Name); Quality = 5,
SellIn = 30
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(4));
}
[Test]
public void UpdateQuality_LowersItemSellInBy1()
{
var item = new Item
{
Name = "test",
Quality = 5,
SellIn = 30
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.SellIn, Is.EqualTo(29));
}
[Test]
public void UpdateQuality_ItemWithZeroSellIn_LowersItemQualityBy2()
{
var item = new Item
{
Name = "test",
Quality = 5,
SellIn = 0
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(3));
}
[Test]
public void UpdateQuality_ItemWithZeroQuality_StayAtZeroQuality()
{
var item = new Item
{
Name = "test",
Quality = 0,
SellIn = 30
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(0));
}
[Test]
public void UpdateQuality_AgedBrie_IncreaseQualityBy1()
{
var item = new Item
{
Name = "Aged Brie",
Quality = 0,
SellIn = 30
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(1));
}
[Test]
public void UpdateQuality_AgedBrieWith50Quality_StayAt50Quality()
{
var item = new Item
{
Name = "Aged Brie",
Quality = 50,
SellIn = 30
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(50));
}
[Test]
public void UpdateQuality_Sulfuras_DoesNotDecreaseQuality()
{
var item = new Item
{
Name = "Sulfuras, Hand of Ragnaros",
Quality = 80,
SellIn = 30
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(80));
}
[Test]
public void UpdateQuality_Sulfuras_DoesNotDecreaseSellIn()
{
var item = new Item
{
Name = "Sulfuras, Hand of Ragnaros",
Quality = 80,
SellIn = 30
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.SellIn, Is.EqualTo(30));
}
[Test]
public void UpdateQuality_BackstagePassesWithMoreThan10DaysLeft_IncreasesQualityBy1()
{
var item = new Item
{
Name = "Backstage passes to a TAFKAL80ETC concert",
Quality = 35,
SellIn = 11
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(36));
}
[Test]
public void UpdateQuality_BackstagePassesWith10DaysLeft_IncreasesQualityBy2()
{
var item = new Item
{
Name = "Backstage passes to a TAFKAL80ETC concert",
Quality = 35,
SellIn = 10
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(37));
}
[Test]
public void UpdateQuality_BackstagePassesWith5DaysLeft_IncreasesQualityBy3()
{
var item = new Item
{
Name = "Backstage passes to a TAFKAL80ETC concert",
Quality = 35,
SellIn = 5
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(38));
}
[Test]
public void UpdateQuality_BackstagePassesWith0DaysLeft_SetQualityToZero()
{
var item = new Item
{
Name = "Backstage passes to a TAFKAL80ETC concert",
Quality = 35,
SellIn = 0
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(0));
}
[Test]
public void UpdateQuality_ConjuredItemWithSellIn4_DecreasesQualityBy2()
{
var item = new Item
{
Name = "Conjured Mana Cake",
Quality = 35,
SellIn = 4
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(33));
}
[Test]
public void UpdateQuality_ConjuredItemWithSellIn0_DecreasesQualityBy4()
{
var item = new Item
{
Name = "Conjured Mana Cake",
Quality = 35,
SellIn = 0
};
var items = new List<Item>(new[] { item });
var gRose = new GildedRose(items);
gRose.UpdateQuality();
Assert.That(item.Quality, Is.EqualTo(31));
} }
} }
} }