From b236c1e9f4db0361d7b5d51d883a94028473c3a9 Mon Sep 17 00:00:00 2001 From: "david.wolfson" Date: Mon, 7 Oct 2024 15:25:58 +0100 Subject: [PATCH] added 5 & 10 day tests --- go/bug.md | 43 +++++++++++++++ go/gildedrose/gildedrose_test.go | 90 +++++++++++++++++++++++++++++++- go/texttest_fixture.go | 4 +- 3 files changed, 134 insertions(+), 3 deletions(-) create mode 100644 go/bug.md diff --git a/go/bug.md b/go/bug.md new file mode 100644 index 0000000000..e845befcaf --- /dev/null +++ b/go/bug.md @@ -0,0 +1,43 @@ +# A list of observed potential bugs to investigate + +## Conjured Items + +"We have recently signed a supplier of conjured items. This requires an update to our system: +"Conjured" items degrade in Quality twice as fast as normal items" + +``` +>go run texttest_fixture.go 5 +... + +-------- day 0 -------- +Name, SellIn, Quality +... +&{Conjured Mana Cake 3 6} + +... +-------- day 1 -------- +&{Conjured Mana Cake 2 5} + +... +-------- day 2 -------- +&{Conjured Mana Cake 1 4} + +... +-------- day 3 -------- +&{Conjured Mana Cake 0 3} +... +-------- day 4 -------- +&{Conjured Mana Cake -1 1} +... +-------- day 5 -------- +&{Conjured Mana Cake -2 0} + +``` + +Appears that Qaulity jumps by 2 on data 4 (i.e. quality is never 2) + +## aged brie + +"Once the sell by date has passed, Quality degrades twice as fast" +"Aged Brie" actually increases in Quality the older it gets +initial behaviour is that quality increases twice as fast after SellIn diff --git a/go/gildedrose/gildedrose_test.go b/go/gildedrose/gildedrose_test.go index 70eaceddbb..6e60202476 100644 --- a/go/gildedrose/gildedrose_test.go +++ b/go/gildedrose/gildedrose_test.go @@ -41,7 +41,7 @@ func Test_oneDay(t *testing.T) { {"Backstage passes to a TAFKAL80ETC concert", 15, 20}, {"Backstage passes to a TAFKAL80ETC concert", 10, 49}, {"Backstage passes to a TAFKAL80ETC concert", 5, 49}, - {"Conjured Mana Cake", 3, 6}, // <-- :O + {"Conjured Mana Cake", 3, 6}, } var expected = []*gildedrose.Item{ @@ -73,3 +73,91 @@ func Test_oneDay(t *testing.T) { } } + +func Test_twoDays(t *testing.T) { + // Arrange + var items = []*gildedrose.Item{ + {"+5 Dexterity Vest", 10, 20}, + {"Aged Brie", 2, 0}, + {"Elixir of the Mongoose", 5, 7}, + {"Sulfuras, Hand of Ragnaros", 0, 80}, + {"Sulfuras, Hand of Ragnaros", -1, 80}, + {"Backstage passes to a TAFKAL80ETC concert", 15, 20}, + {"Backstage passes to a TAFKAL80ETC concert", 10, 49}, + {"Backstage passes to a TAFKAL80ETC concert", 5, 49}, + {"Conjured Mana Cake", 3, 6}, + } + + var expected = []*gildedrose.Item{ + {"+5 Dexterity Vest", 8, 18}, + {"Aged Brie", 0, 2}, + {"Elixir of the Mongoose", 3, 5}, + {"Sulfuras, Hand of Ragnaros", 0, 80}, + {"Sulfuras, Hand of Ragnaros", -1, 80}, + {"Backstage passes to a TAFKAL80ETC concert", 13, 22}, + {"Backstage passes to a TAFKAL80ETC concert", 8, 50}, + {"Backstage passes to a TAFKAL80ETC concert", 3, 50}, + {"Conjured Mana Cake", 1, 4}, // <-- :O + } + + // Act + gildedrose.UpdateQuality(items) + gildedrose.UpdateQuality(items) + + // Assert + for i, item := range expected { + if items[i].Name != item.Name { + t.Errorf("Name: Expected %s but got %s ", item.Name, items[i].Name) + } + if items[i].SellIn != item.SellIn { + t.Errorf("%s - SellIn: Expected %d but got %d ", item.Name, item.SellIn, items[i].SellIn) + } + if items[i].Quality != item.Quality { + t.Errorf("%s - Quality: Expected %d but got %d ", item.Name, item.Quality, items[i].Quality) + } + } +} +func Test_fiveDays(t *testing.T) { + // Arrange + var items = []*gildedrose.Item{ + {"+5 Dexterity Vest", 10, 20}, + {"Aged Brie", 2, 0}, + {"Elixir of the Mongoose", 5, 7}, + {"Sulfuras, Hand of Ragnaros", 0, 80}, + {"Sulfuras, Hand of Ragnaros", -1, 80}, + {"Backstage passes to a TAFKAL80ETC concert", 15, 20}, + {"Backstage passes to a TAFKAL80ETC concert", 10, 49}, + {"Backstage passes to a TAFKAL80ETC concert", 5, 49}, + {"Conjured Mana Cake", 3, 6}, + } + + var expected = []*gildedrose.Item{ + {"+5 Dexterity Vest", 0, 10}, + {"Aged Brie", -8, 18}, + {"Elixir of the Mongoose", -5, 0}, + {"Sulfuras, Hand of Ragnaros", 0, 80}, + {"Sulfuras, Hand of Ragnaros", -1, 80}, + {"Backstage passes to a TAFKAL80ETC concert", 5, 35}, + {"Backstage passes to a TAFKAL80ETC concert", 0, 50}, + {"Backstage passes to a TAFKAL80ETC concert", -5, 0}, + {"Conjured Mana Cake", -7, 0}, // <-- :O + } + + // Act + for day := 1; day <= 10; day++ { + gildedrose.UpdateQuality(items) + } + + // Assert + for i, item := range expected { + if items[i].Name != item.Name { + t.Errorf("Name: Expected %s but got %s ", item.Name, items[i].Name) + } + if items[i].SellIn != item.SellIn { + t.Errorf("%s - SellIn: Expected %d but got %d ", item.Name, item.SellIn, items[i].SellIn) + } + if items[i].Quality != item.Quality { + t.Errorf("%s - Quality: Expected %d but got %d ", item.Name, item.Quality, items[i].Quality) + } + } +} diff --git a/go/texttest_fixture.go b/go/texttest_fixture.go index cee5082f42..5c96506493 100644 --- a/go/texttest_fixture.go +++ b/go/texttest_fixture.go @@ -12,8 +12,8 @@ func main() { fmt.Println("OMGHAI!") var items = []*gildedrose.Item{ - {Name: "+5 Dexterity Vest", SellIn: 10, Quality: 20}, - {Name: "Aged Brie", SellIn: 2, Quality: 0}, + {"+5 Dexterity Vest", 10, 20}, + {"Aged Brie", 2, 0}, {"Elixir of the Mongoose", 5, 7}, {"Sulfuras, Hand of Ragnaros", 0, 80}, {"Sulfuras, Hand of Ragnaros", -1, 80},