mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
add min function
This commit is contained in:
parent
afa3d43717
commit
6a651a5f7a
@ -5,11 +5,43 @@ type Item struct {
|
|||||||
sellIn, quality int
|
sellIn, quality int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func min(x int, y int) int {
|
||||||
|
if x == y {
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
if x < y {
|
||||||
|
return x
|
||||||
|
}
|
||||||
|
return y
|
||||||
|
}
|
||||||
|
|
||||||
func UpdateQualityBrie(item *Item) {
|
func UpdateQualityBrie(item *Item) {
|
||||||
defer func() {
|
defer func() {
|
||||||
item.sellIn = item.sellIn - 1
|
item.sellIn--
|
||||||
}()
|
}()
|
||||||
|
|
||||||
|
if item.quality == 50 {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
if item.sellIn > 0 {
|
||||||
|
item.quality++
|
||||||
|
}
|
||||||
|
if item.sellIn <= 0 {
|
||||||
|
item.quality = min(item.quality+2, 50)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
func UpdateQualityBackstagePasses(item *Item) {
|
||||||
|
defer func() {
|
||||||
|
item.sellIn--
|
||||||
|
}()
|
||||||
|
|
||||||
|
if item.sellIn <= 0 {
|
||||||
|
item.quality = 0
|
||||||
|
}
|
||||||
|
|
||||||
if item.quality == 50 {
|
if item.quality == 50 {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user