mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Fixed AgedBrieItemUpdateService; updated BackstagePassItemUpdateService
This commit is contained in:
parent
b2724c7438
commit
5c5a441914
@ -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
|
||||
}
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
@ -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)
|
||||
})
|
||||
|
||||
Loading…
Reference in New Issue
Block a user