mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
add comments
This commit is contained in:
parent
c63614cc15
commit
ceda8ff096
@ -32,17 +32,21 @@ func max(x int, y int) int {
|
|||||||
|
|
||||||
// UpdateQualityBrie handles updates for aged brie
|
// UpdateQualityBrie handles updates for aged brie
|
||||||
func UpdateQualityBrie(item *Item) {
|
func UpdateQualityBrie(item *Item) {
|
||||||
|
// always decrement sellInn
|
||||||
defer func() {
|
defer func() {
|
||||||
item.sellIn--
|
item.sellIn--
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// quality cannot go above 50
|
||||||
if item.quality == 50 {
|
if item.quality == 50 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// increment when prior to sellIn
|
||||||
if item.sellIn > 0 {
|
if item.sellIn > 0 {
|
||||||
item.quality++
|
item.quality++
|
||||||
}
|
}
|
||||||
|
// increment by 2 if past sellInn date
|
||||||
if item.sellIn <= 0 {
|
if item.sellIn <= 0 {
|
||||||
item.quality = min(item.quality+2, 50)
|
item.quality = min(item.quality+2, 50)
|
||||||
}
|
}
|
||||||
@ -51,55 +55,66 @@ func UpdateQualityBrie(item *Item) {
|
|||||||
|
|
||||||
// UpdateQualityBackstagePasses handles updates for backstage passes
|
// UpdateQualityBackstagePasses handles updates for backstage passes
|
||||||
func UpdateQualityBackstagePasses(item *Item) {
|
func UpdateQualityBackstagePasses(item *Item) {
|
||||||
|
// always decrement sellInn
|
||||||
defer func() {
|
defer func() {
|
||||||
item.sellIn--
|
item.sellIn--
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// if past sellInn date then item is worthless
|
||||||
if item.sellIn <= 0 {
|
if item.sellIn <= 0 {
|
||||||
item.quality = 0
|
item.quality = 0
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// increment by 3 under with under 5 days to go
|
||||||
if item.sellIn <= 5 {
|
if item.sellIn <= 5 {
|
||||||
item.quality = min(item.quality+3, 50)
|
item.quality = min(item.quality+3, 50)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// increment by 2 under with under 10 days to go
|
||||||
if item.sellIn <= 10 {
|
if item.sellIn <= 10 {
|
||||||
item.quality = min(item.quality+2, 50)
|
item.quality = min(item.quality+2, 50)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// increment by 1 under normal conditions
|
||||||
item.quality++
|
item.quality++
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateQualityStandard handles updates for standard items
|
// UpdateQualityStandard handles updates for standard items
|
||||||
func UpdateQualityStandard(item *Item) {
|
func UpdateQualityStandard(item *Item) {
|
||||||
|
// always decrement sellInn
|
||||||
defer func() {
|
defer func() {
|
||||||
item.sellIn--
|
item.sellIn--
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// if past sellInn date then decrement by 2
|
||||||
if item.sellIn <= 0 {
|
if item.sellIn <= 0 {
|
||||||
item.quality = max(item.quality-2, 0)
|
item.quality = max(item.quality-2, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decrement by 1
|
||||||
item.quality = max(item.quality-1, 0)
|
item.quality = max(item.quality-1, 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// UpdateQualityConjured handles updates for conjured items
|
// UpdateQualityConjured handles updates for conjured items
|
||||||
func UpdateQualityConjured(item *Item) {
|
func UpdateQualityConjured(item *Item) {
|
||||||
|
// always decrement sellInn
|
||||||
defer func() {
|
defer func() {
|
||||||
item.sellIn--
|
item.sellIn--
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
// if past sellInn date then decrement by 4
|
||||||
if item.sellIn <= 0 {
|
if item.sellIn <= 0 {
|
||||||
item.quality = max(item.quality-4, 0)
|
item.quality = max(item.quality-4, 0)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// decrement by 2
|
||||||
item.quality = max(item.quality-2, 0)
|
item.quality = max(item.quality-2, 0)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user