mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
separate brie update
This commit is contained in:
parent
3d90e599d7
commit
afa3d43717
14
go/README.md
14
go/README.md
@ -18,4 +18,16 @@ go test
|
||||
go test -coverprofile=coverage.out
|
||||
|
||||
go tool cover -html=coverage.out
|
||||
```
|
||||
```
|
||||
|
||||
- Create golden test file using textest (*nix):
|
||||
|
||||
```bash
|
||||
go run texttest_fixture.go gilded-rose.go > golden_test.txt
|
||||
```
|
||||
|
||||
- Testing changes against the golden test file (*nix):
|
||||
|
||||
```bash
|
||||
diff <(go run texttest_fixture.go gilded-rose.go) golden_test.txt
|
||||
```
|
||||
|
||||
@ -5,14 +5,41 @@ type Item struct {
|
||||
sellIn, quality int
|
||||
}
|
||||
|
||||
func UpdateQualityBrie(item *Item) {
|
||||
defer func() {
|
||||
item.sellIn = item.sellIn - 1
|
||||
}()
|
||||
|
||||
if item.quality == 50 {
|
||||
return
|
||||
}
|
||||
if item.quality == 49 && item.sellIn <= 0 {
|
||||
item.quality = 50
|
||||
}
|
||||
if item.sellIn > 0 {
|
||||
item.quality++
|
||||
}
|
||||
if item.sellIn <= 0 {
|
||||
item.quality += 2
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func UpdateQuality(items []*Item) {
|
||||
for i := 0; i < len(items); i++ {
|
||||
|
||||
if items[i].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||
if items[i].name == "Sulfuras, Hand of Ragnaros" {
|
||||
continue
|
||||
}
|
||||
|
||||
if items[i].name == "Aged Brie" {
|
||||
UpdateQualityBrie(items[i])
|
||||
continue
|
||||
}
|
||||
|
||||
if items[i].name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||
if items[i].quality > 0 {
|
||||
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
||||
items[i].quality = items[i].quality - 1
|
||||
}
|
||||
items[i].quality = items[i].quality - 1
|
||||
}
|
||||
} else {
|
||||
if items[i].quality < 50 {
|
||||
@ -32,17 +59,13 @@ func UpdateQuality(items []*Item) {
|
||||
}
|
||||
}
|
||||
|
||||
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
||||
items[i].sellIn = items[i].sellIn - 1
|
||||
}
|
||||
items[i].sellIn = items[i].sellIn - 1
|
||||
|
||||
if items[i].sellIn < 0 {
|
||||
if items[i].name != "Aged Brie" {
|
||||
if items[i].name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||
if items[i].quality > 0 {
|
||||
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
||||
items[i].quality = items[i].quality - 1
|
||||
}
|
||||
items[i].quality = items[i].quality - 1
|
||||
}
|
||||
} else {
|
||||
items[i].quality = items[i].quality - items[i].quality
|
||||
|
||||
@ -43,7 +43,7 @@ func Test_Items(t *testing.T) {
|
||||
for i, item := range items {
|
||||
actual := [2]int{item.sellIn, item.quality}
|
||||
if actual != expected[i] {
|
||||
t.Errorf("Expected %+v but got %+v", expected[i], actual)
|
||||
t.Errorf("%s: Expected %+v but got %+v", item.name, expected[i], actual)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user