mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 22:41:30 +00:00
Merge c9668452c4 into e916fdd8ac
This commit is contained in:
commit
dd48a51d01
@ -1,7 +0,0 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_GildedRose(t *testing.T) {
|
||||
main()
|
||||
}
|
||||
90
go/gilded_rose.go
Normal file
90
go/gilded_rose.go
Normal file
@ -0,0 +1,90 @@
|
||||
package main
|
||||
|
||||
import "fmt"
|
||||
|
||||
type GildedRose struct {
|
||||
Items []Item
|
||||
}
|
||||
|
||||
type Item struct {
|
||||
Name string
|
||||
SellIn, Quality int
|
||||
}
|
||||
|
||||
func main() {
|
||||
rose := GildedRose{
|
||||
[]Item{
|
||||
Item{"+5 Dexterity Vest", 10, 20},
|
||||
Item{"Aged Brie", 2, 0},
|
||||
Item{"Elixir of the Mongoose", 5, 7},
|
||||
Item{"Sulfuras, Hand of Ragnaros", 0, 80},
|
||||
Item{"Backstage passes to a TAFKAL80ETC concert", 15, 20},
|
||||
Item{"Conjured Mana Cake", 3, 6},
|
||||
},
|
||||
}
|
||||
rose.UpdateQuality()
|
||||
fmt.Print(rose.String())
|
||||
}
|
||||
|
||||
func (gr *GildedRose) UpdateQuality() {
|
||||
|
||||
for i := 0; i < len(gr.Items); i++ {
|
||||
item := &gr.Items[i]
|
||||
|
||||
if item.Name != "Aged Brie" && item.Name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||
if item.Quality > 0 {
|
||||
if item.Name != "Sulfuras, Hand of Ragnaros" {
|
||||
item.Quality = item.Quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if item.Quality < 50 {
|
||||
item.Quality = item.Quality + 1
|
||||
if item.Name == "Backstage passes to a TAFKAL80ETC concert" {
|
||||
if item.SellIn < 11 {
|
||||
if item.Quality < 50 {
|
||||
item.Quality = item.Quality + 1
|
||||
}
|
||||
}
|
||||
if item.SellIn < 6 {
|
||||
if item.Quality < 50 {
|
||||
item.Quality = item.Quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if item.Name != "Sulfuras, Hand of Ragnaros" {
|
||||
item.SellIn = item.SellIn - 1
|
||||
}
|
||||
|
||||
if item.SellIn < 0 {
|
||||
if item.Name != "Aged Brie" {
|
||||
if item.Name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||
if item.Quality > 0 {
|
||||
if item.Name != "Sulfuras, Hand of Ragnaros" {
|
||||
item.Quality = item.Quality - 1
|
||||
}
|
||||
}
|
||||
} else {
|
||||
item.Quality = item.Quality - item.Quality
|
||||
}
|
||||
} else {
|
||||
if item.Quality < 50 {
|
||||
item.Quality = item.Quality + 1
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (gr *GildedRose) String() string {
|
||||
var str string
|
||||
str += "=== The Gilded Rose ===\n"
|
||||
for i, item := range gr.Items {
|
||||
str += fmt.Sprintf("%d) %s (quality %d, sell in %d)\n", i+1, item.Name, item.Quality, item.SellIn)
|
||||
}
|
||||
return str
|
||||
}
|
||||
12
go/gilded_rose_test.go
Normal file
12
go/gilded_rose_test.go
Normal file
@ -0,0 +1,12 @@
|
||||
package main
|
||||
|
||||
import "testing"
|
||||
|
||||
func Test_GildedRose_UpdateQuality_DoesNotChangeItemName(t *testing.T) {
|
||||
rose := GildedRose{[]Item{Item{"Foo", 0, 0}}}
|
||||
expectedName := "Fixme"
|
||||
rose.UpdateQuality()
|
||||
if rose.Items[0].Name != expectedName {
|
||||
t.Errorf("Expected Item name to be %#v (got %#v)", expectedName, rose.Items[0].Name)
|
||||
}
|
||||
}
|
||||
16
go/readme.md
16
go/readme.md
@ -1,21 +1,19 @@
|
||||
# GO Starter
|
||||
# Go Starter
|
||||
|
||||
- Run :
|
||||
- Run:
|
||||
|
||||
```shell
|
||||
go run gilded-rose.go
|
||||
go run gilded_rose.go
|
||||
```
|
||||
|
||||
- Run tests :
|
||||
- Run tests:
|
||||
|
||||
```shell
|
||||
go test
|
||||
```
|
||||
|
||||
- Run tests and coverage :
|
||||
- Run tests and coverage:
|
||||
|
||||
```shell
|
||||
go test -coverprofile=coverage.out
|
||||
|
||||
go tool cover -html=coverage.out
|
||||
```
|
||||
go test -cover
|
||||
```
|
||||
|
||||
Loading…
Reference in New Issue
Block a user