Merge pull request #326 from myugen/feature/update_go

feat: update go boilerplate
This commit is contained in:
Emily Bache 2022-04-27 08:04:46 +02:00 committed by GitHub
commit 0959363685
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 97 additions and 88 deletions

View File

@ -3,19 +3,19 @@
- Run :
```shell
go run texttest_fixture.go gilded-rose.go
go run texttest_fixture.go [<number-of-days>; default: 2]
```
- Run tests :
```shell
go test
go test ./...
```
- Run tests and coverage :
```shell
go test -coverprofile=coverage.out
go test ./... -coverprofile=coverage.out
go tool cover -html=coverage.out
```

View File

@ -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
}
}
}
}
}

View File

@ -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)
}
}

View 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
}
}
}
}
}

View 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
View File

@ -0,0 +1,3 @@
module github.com/emilybache/gildedrose-refactoring-kata
go 1.18

View File

@ -4,21 +4,23 @@ import (
"fmt"
"os"
"strconv"
"github.com/emilybache/gildedrose-refactoring-kata/gildedrose"
)
func main() {
fmt.Println("OMGHAI!")
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{"Sulfuras, Hand of Ragnaros", -1, 80},
&Item{"Backstage passes to a TAFKAL80ETC concert", 15, 20},
&Item{"Backstage passes to a TAFKAL80ETC concert", 10, 49},
&Item{"Backstage passes to a TAFKAL80ETC concert", 5, 49},
&Item{"Conjured Mana Cake", 3, 6}, // <-- :O
var items = []*gildedrose.Item{
{"+5 Dexterity Vest", 10, 20},
{"Aged Brie", 2, 0},
{"Elixir of the Mongoose", 5, 7},
{"Sulfuras, Hand of Ragnaros", 0, 80},
{"Sulfuras, Hand of Ragnaros", -1, 80},
{"Backstage passes to a TAFKAL80ETC concert", 15, 20},
{"Backstage passes to a TAFKAL80ETC concert", 10, 49},
{"Backstage passes to a TAFKAL80ETC concert", 5, 49},
{"Conjured Mana Cake", 3, 6}, // <-- :O
}
days := 2
@ -34,11 +36,11 @@ func main() {
for day := 0; day < days; day++ {
fmt.Printf("-------- day %d --------\n", day)
fmt.Println("name, sellIn, quality")
fmt.Println("Name, SellIn, Quality")
for i := 0; i < len(items); i++ {
fmt.Println(items[i])
}
fmt.Println("")
UpdateQuality(items)
gildedrose.UpdateQuality(items)
}
}