mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
feat: update go boilerplate
This commit is contained in:
parent
181b48aff7
commit
f6fe61daac
@ -3,19 +3,19 @@
|
|||||||
- Run :
|
- Run :
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go run texttest_fixture.go gilded-rose.go
|
go run texttest_fixture.go [<number-of-days>; default: 2]
|
||||||
```
|
```
|
||||||
|
|
||||||
- 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 ./... -coverprofile=coverage.out
|
||||||
|
|
||||||
go tool cover -html=coverage.out
|
go tool cover -html=coverage.out
|
||||||
```
|
```
|
||||||
@ -1,58 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
type Item struct {
|
|
||||||
name string
|
|
||||||
sellIn, quality int
|
|
||||||
}
|
|
||||||
|
|
||||||
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].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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
package main
|
|
||||||
|
|
||||||
import "testing"
|
|
||||||
|
|
||||||
func Test_Foo(t *testing.T) {
|
|
||||||
var items = []*Item{
|
|
||||||
&Item{"foo", 0, 0},
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateQuality(items)
|
|
||||||
|
|
||||||
if items[0].name != "fixme" {
|
|
||||||
t.Errorf("Name: Expected %s but got %s ", "fixme", items[0].name)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
58
go/gildedrose/gildedrose.go
Normal file
58
go/gildedrose/gildedrose.go
Normal file
@ -0,0 +1,58 @@
|
|||||||
|
package gildedrose
|
||||||
|
|
||||||
|
type Item struct {
|
||||||
|
Name string
|
||||||
|
SellIn, Quality int
|
||||||
|
}
|
||||||
|
|
||||||
|
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].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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
19
go/gildedrose/gildedrose_test.go
Normal file
19
go/gildedrose/gildedrose_test.go
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
package gildedrose_test
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"github.com/emilybache/gildedrose-refactoring-kata/gildedrose"
|
||||||
|
)
|
||||||
|
|
||||||
|
func Test_Foo(t *testing.T) {
|
||||||
|
var items = []*gildedrose.Item{
|
||||||
|
{"foo", 0, 0},
|
||||||
|
}
|
||||||
|
|
||||||
|
gildedrose.UpdateQuality(items)
|
||||||
|
|
||||||
|
if items[0].Name != "fixme" {
|
||||||
|
t.Errorf("Name: Expected %s but got %s ", "fixme", items[0].Name)
|
||||||
|
}
|
||||||
|
}
|
||||||
3
go/go.mod
Normal file
3
go/go.mod
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
module github.com/emilybache/gildedrose-refactoring-kata
|
||||||
|
|
||||||
|
go 1.18
|
||||||
@ -4,21 +4,23 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"strconv"
|
"strconv"
|
||||||
|
|
||||||
|
"github.com/emilybache/gildedrose-refactoring-kata/gildedrose"
|
||||||
)
|
)
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
fmt.Println("OMGHAI!")
|
fmt.Println("OMGHAI!")
|
||||||
|
|
||||||
var items = []*Item{
|
var items = []*gildedrose.Item{
|
||||||
&Item{"+5 Dexterity Vest", 10, 20},
|
{"+5 Dexterity Vest", 10, 20},
|
||||||
&Item{"Aged Brie", 2, 0},
|
{"Aged Brie", 2, 0},
|
||||||
&Item{"Elixir of the Mongoose", 5, 7},
|
{"Elixir of the Mongoose", 5, 7},
|
||||||
&Item{"Sulfuras, Hand of Ragnaros", 0, 80},
|
{"Sulfuras, Hand of Ragnaros", 0, 80},
|
||||||
&Item{"Sulfuras, Hand of Ragnaros", -1, 80},
|
{"Sulfuras, Hand of Ragnaros", -1, 80},
|
||||||
&Item{"Backstage passes to a TAFKAL80ETC concert", 15, 20},
|
{"Backstage passes to a TAFKAL80ETC concert", 15, 20},
|
||||||
&Item{"Backstage passes to a TAFKAL80ETC concert", 10, 49},
|
{"Backstage passes to a TAFKAL80ETC concert", 10, 49},
|
||||||
&Item{"Backstage passes to a TAFKAL80ETC concert", 5, 49},
|
{"Backstage passes to a TAFKAL80ETC concert", 5, 49},
|
||||||
&Item{"Conjured Mana Cake", 3, 6}, // <-- :O
|
{"Conjured Mana Cake", 3, 6}, // <-- :O
|
||||||
}
|
}
|
||||||
|
|
||||||
days := 2
|
days := 2
|
||||||
@ -34,11 +36,11 @@ func main() {
|
|||||||
|
|
||||||
for day := 0; day < days; day++ {
|
for day := 0; day < days; day++ {
|
||||||
fmt.Printf("-------- day %d --------\n", day)
|
fmt.Printf("-------- day %d --------\n", day)
|
||||||
fmt.Println("name, sellIn, quality")
|
fmt.Println("Name, SellIn, Quality")
|
||||||
for i := 0; i < len(items); i++ {
|
for i := 0; i < len(items); i++ {
|
||||||
fmt.Println(items[i])
|
fmt.Println(items[i])
|
||||||
}
|
}
|
||||||
fmt.Println("")
|
fmt.Println("")
|
||||||
UpdateQuality(items)
|
gildedrose.UpdateQuality(items)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user