diff --git a/go/services/aged_brie_item_update_service.go b/go/services/aged_brie_item_update_service.go index e598ce32..15a9b1b3 100644 --- a/go/services/aged_brie_item_update_service.go +++ b/go/services/aged_brie_item_update_service.go @@ -19,53 +19,13 @@ func (this AgedBrieItemUpdateService) UpdateQuality(item *models.Item) error { item.Mutex.Lock() defer item.Mutex.Unlock() - itemModel := item.Model - - if itemModel.Name != "Aged Brie" && itemModel.Name != "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.Quality > 0 { - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.Quality = itemModel.Quality - 1 - } - } - } else { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - if itemModel.Name == "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.SellIn < 11 { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } - } - if itemModel.SellIn < 6 { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } - } - } - } + if item.Model.Quality < 50 { + item.Model.Quality++ } - - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.SellIn = itemModel.SellIn - 1 - } - - if itemModel.SellIn < 0 { - if itemModel.Name != "Aged Brie" { - if itemModel.Name != "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.Quality > 0 { - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.Quality = itemModel.Quality - 1 - } - } - } else { - itemModel.Quality = itemModel.Quality - itemModel.Quality - } - } else { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } - } + if item.Model.SellIn <= 0 && item.Model.Quality < 50 { + item.Model.Quality++ } + item.Model.SellIn-- return nil } diff --git a/go/services/backstage_pass_item_update_service.go b/go/services/backstage_pass_item_update_service.go index 910511d3..8b168ada 100644 --- a/go/services/backstage_pass_item_update_service.go +++ b/go/services/backstage_pass_item_update_service.go @@ -19,53 +19,22 @@ func (this BackstagePassItemUpdateService) UpdateQuality(item *models.Item) erro item.Mutex.Lock() defer item.Mutex.Unlock() - itemModel := item.Model - - if itemModel.Name != "Aged Brie" && itemModel.Name != "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.Quality > 0 { - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.Quality = itemModel.Quality - 1 - } - } + if item.Model.SellIn <= 0 { + item.Model.Quality = 0 } else { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - if itemModel.Name == "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.SellIn < 11 { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } - } - if itemModel.SellIn < 6 { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } - } - } + increment := 1 + if item.Model.SellIn <= 5 { + increment = 3 + } else if item.Model.SellIn <= 10 { + increment = 2 } - } - - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.SellIn = itemModel.SellIn - 1 - } - - if itemModel.SellIn < 0 { - if itemModel.Name != "Aged Brie" { - if itemModel.Name != "Backstage passes to a TAFKAL80ETC concert" { - if itemModel.Quality > 0 { - if itemModel.Name != "Sulfuras, Hand of Ragnaros" { - itemModel.Quality = itemModel.Quality - 1 - } - } - } else { - itemModel.Quality = itemModel.Quality - itemModel.Quality - } + if (item.Model.Quality + increment) > 50 { + item.Model.Quality = 50 } else { - if itemModel.Quality < 50 { - itemModel.Quality = itemModel.Quality + 1 - } + item.Model.Quality += increment } } + item.Model.SellIn-- return nil } diff --git a/go/services/backstage_pass_item_update_service_test.go b/go/services/backstage_pass_item_update_service_test.go index c2c5f1e2..243e30f9 100644 --- a/go/services/backstage_pass_item_update_service_test.go +++ b/go/services/backstage_pass_item_update_service_test.go @@ -62,12 +62,23 @@ func TestBackstagePassItemUpdateService_QualityAfterSellIn4Days(t *testing.T) { }) } +// Quality must not be greater than 50 +func TestBackstagePassItemUpdateService_QualityNotHigherThan50(t *testing.T) { + runTestCase(t, func( + backstagePassItemUpdateService BackstagePassItemUpdateService, + ) { + item := models.NewItem(&models.ItemModel{"Backstage passes to a TAFKAL80ETC concert", 1, 50}) + backstagePassItemUpdateService.UpdateQuality(item) + assert.Equal(t, 50, item.Model.Quality) + }) +} + // sellIn date must decrease func TestBackstagePassItemUpdateService_SellInIsDecreased(t *testing.T) { runTestCase(t, func( backstagePassItemUpdateService BackstagePassItemUpdateService, ) { - item := models.NewItem(&models.ItemModel{"Random normal item", -4, 0}) + item := models.NewItem(&models.ItemModel{"Backstage passes to a TAFKAL80ETC concert", -4, 0}) backstagePassItemUpdateService.UpdateQuality(item) assert.Equal(t, -5, item.Model.SellIn) })