mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2026-02-15 14:31:28 +00:00
Fix file names, golang conventions, and example test.
This commit is contained in:
parent
acf452f9c9
commit
c9668452c4
@ -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)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,75 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
type Item struct {
|
|
||||||
name string
|
|
||||||
sellIn, quality int
|
|
||||||
}
|
|
||||||
|
|
||||||
var items = []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},
|
|
||||||
}
|
|
||||||
|
|
||||||
func main() {
|
|
||||||
fmt.Println("OMGHAI!")
|
|
||||||
// fmt.Print(items)
|
|
||||||
GlidedRose()
|
|
||||||
}
|
|
||||||
|
|
||||||
func GlidedRose() {
|
|
||||||
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].quality > 0 {
|
|
||||||
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
|
||||||
items[i].quality = items[i].quality - 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if items[i].quality < 50 {
|
|
||||||
items[i].quality = items[i].quality + 1
|
|
||||||
if items[i].name == "Backstage passes to a TAFKAL80ETC concert" {
|
|
||||||
if items[i].sellIn < 11 {
|
|
||||||
if items[i].quality < 50 {
|
|
||||||
items[i].quality = items[i].quality + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if items[i].sellIn < 6 {
|
|
||||||
if items[i].quality < 50 {
|
|
||||||
items[i].quality = items[i].quality + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if items[i].name != "Sulfuras, Hand of Ragnaros" {
|
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
items[i].quality = items[i].quality - items[i].quality
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if items[i].quality < 50 {
|
|
||||||
items[i].quality = items[i].quality + 1
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
16
go/readme.md
16
go/readme.md
@ -1,21 +1,19 @@
|
|||||||
# GO Starter
|
# Go Starter
|
||||||
|
|
||||||
- Run :
|
- Run:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go run gilded-rose.go
|
go run gilded_rose.go
|
||||||
```
|
```
|
||||||
|
|
||||||
- Run tests :
|
- Run tests:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go test
|
go test
|
||||||
```
|
```
|
||||||
|
|
||||||
- Run tests and coverage :
|
- Run tests and coverage:
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go test -coverprofile=coverage.out
|
go test -cover
|
||||||
|
```
|
||||||
go tool cover -html=coverage.out
|
|
||||||
```
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user