Skip to content

Instantly share code, notes, and snippets.

@adelatorrefoss
Created November 27, 2018 07:27
Show Gist options
  • Select an option

  • Save adelatorrefoss/6c974b422e2f81bf733a4c670cb4f9ba to your computer and use it in GitHub Desktop.

Select an option

Save adelatorrefoss/6c974b422e2f81bf733a4c670cb4f9ba to your computer and use it in GitHub Desktop.
A set of tests proposal for Gilded Rose Kata.
using System;
using System.Collections.Generic;
using Gilded_rose;
using Xunit;
namespace KataGildedRose.Tests
{
public class GildedRoseTest
{
string BACKSTAGE_NAME = "Backstage passes to a TAFKAL80ETC concert";
string NORMAL_ITEM_NAME = "foo";
string AGED_BRIE_NAME = "Aged Brie";
string SULFURAS_NAME = "Sulfuras, Hand of Ragnaros";
int QUALITY_CHANGE = 1;
int NORMAL_ITEM_QUALITY = 5;
int MINIMUM_QUALITY = 0;
int MAXIMUM_QUALITY = 50;
int SELL_IN_CHANGE = 1;
int EXPIRED_SELL_IN = 0;
int NORMAL_ITEM_SELL_IN = 15;
int SELL_IN_IN_5_DAYS = 5;
int SELL_IN_IN_10_DAYS = 10;
[Fact]
public void sell_in_decreases_every_day()
{
VerifySellIn(NORMAL_ITEM_SELL_IN - SELL_IN_CHANGE, NormalItem());
}
[Fact]
public void quality_decreases_every_day()
{
VerifyQuality(NORMAL_ITEM_QUALITY - QUALITY_CHANGE, NormalItem());
}
[Fact]
public void quality_decreases_twice_as_fast_one_sell_in_has_passed()
{
VerifyQuality(NORMAL_ITEM_QUALITY - 2 * QUALITY_CHANGE, ExpiredItem());
}
[Fact]
public void quality_is_never_negative()
{
VerifyQuality(MINIMUM_QUALITY, ItemWithoutQuality());
}
[Fact]
public void aged_brie_increases_quality()
{
VerifyQuality(NORMAL_ITEM_QUALITY + QUALITY_CHANGE, AgedBrie());
}
[Fact]
public void item_never_increase_quality_when_has_reached_the_maximum()
{
VerifyQuality(MAXIMUM_QUALITY, AgedBrieWithMaximumQuality());
}
[Fact]
public void sulfuras_never_changes_the_quality()
{
VerifyQuality(NORMAL_ITEM_QUALITY, Sulfuras());
}
[Fact]
public void sulfuras_never_changes_the_sell_in()
{
VerifySellIn(NORMAL_ITEM_SELL_IN, Sulfuras());
}
[Fact]
public void backstage_increase_quality()
{
VerifyQuality(NORMAL_ITEM_QUALITY + QUALITY_CHANGE, Backstage());
}
[Fact]
public void backstage_increase_quality_by_2_when_sell_in_is_10_or_less()
{
VerifyQuality(NORMAL_ITEM_QUALITY + 2 * QUALITY_CHANGE, BackstageInIn10Days());
}
[Fact]
public void backstage_increase_quality_by_3_when_sell_in_is_5_or_less()
{
VerifyQuality(NORMAL_ITEM_QUALITY + 3 * QUALITY_CHANGE, BackstageIn5Days());
}
[Fact]
public void backstage_drops_to_0_quality_after_the_concert()
{
VerifyQuality(MINIMUM_QUALITY, BackstageAfterTheConcert());
}
[Fact]
public void aged_brie_expired_gets_the_maximum_quality_when_has_the_quality_minus_1()
{
Item item = new Item {Name = AGED_BRIE_NAME, SellIn = EXPIRED_SELL_IN, Quality = MAXIMUM_QUALITY - 1};
VerifyQuality(MAXIMUM_QUALITY, item);
}
private void VerifySellIn(int expectedSellIn, Item item)
{
GildedRose gildedRose = BuildGildedRose(item);
gildedRose.UpdateQuality();
AssertSellIn(expectedSellIn, gildedRose);
}
private void VerifyQuality(int expectedQuality, Item normalItem)
{
GildedRose gildedRose = BuildGildedRose(normalItem);
gildedRose.UpdateQuality();
AssertQuality(expectedQuality, gildedRose);
}
GildedRose BuildGildedRose(Item item)
{
// IList<Item> Items = new List<Item> {
IList<Item> items = new List<Item> {item};
GildedRose app = new GildedRose(items);
return app;
}
private Item NormalItem()
{
return ItemWithNormalSellInAndQuality(NORMAL_ITEM_NAME);
}
private Item ExpiredItem()
{
return ItemWithNormalQuality(NORMAL_ITEM_NAME, EXPIRED_SELL_IN);
}
private Item ItemWithoutQuality()
{
return new Item {Name = NORMAL_ITEM_NAME, SellIn = NORMAL_ITEM_SELL_IN, Quality = MINIMUM_QUALITY};
}
private Item AgedBrie()
{
return ItemWithNormalSellInAndQuality(AGED_BRIE_NAME);
}
private Item AgedBrieWithMaximumQuality()
{
return new Item {Name = AGED_BRIE_NAME, SellIn = NORMAL_ITEM_SELL_IN, Quality = MAXIMUM_QUALITY};
}
private Item Sulfuras()
{
return ItemWithNormalSellInAndQuality(SULFURAS_NAME);
}
private Item Backstage()
{
return ItemWithNormalSellInAndQuality(BACKSTAGE_NAME);
}
private Item BackstageInIn10Days()
{
return ItemWithNormalQuality(BACKSTAGE_NAME, SELL_IN_IN_10_DAYS);
}
private Item BackstageIn5Days()
{
return ItemWithNormalQuality(BACKSTAGE_NAME, SELL_IN_IN_5_DAYS);
}
private Item BackstageAfterTheConcert()
{
return ItemWithNormalQuality(BACKSTAGE_NAME, EXPIRED_SELL_IN);
}
private Item ItemWithNormalSellInAndQuality(String name)
{
return ItemWithNormalQuality(name, NORMAL_ITEM_SELL_IN);
}
private Item ItemWithNormalQuality(String name, int sellIn)
{
return new Item {Name = name, SellIn = sellIn, Quality = NORMAL_ITEM_QUALITY};
}
private static void AssertSellIn(int expectedSellIn, GildedRose app)
{
Assert.Equal(expectedSellIn, app.Items[0].SellIn);
}
private static void AssertQuality(int expectedQuality, GildedRose gildedRose)
{
Assert.Equal(expectedQuality, gildedRose.Items[0].Quality);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment