From f6fe61daacd93dc16e633e3d4d0c4b80f74b317d Mon Sep 17 00:00:00 2001 From: Miguel Ignacio Cabrera San Gil Date: Mon, 25 Apr 2022 23:09:29 +0100 Subject: [PATCH] feat: update go boilerplate --- go/README.md | 6 ++-- go/gilded-rose.go | 58 -------------------------------- go/gilded-rose_test.go | 15 --------- go/gildedrose/gildedrose.go | 58 ++++++++++++++++++++++++++++++++ go/gildedrose/gildedrose_test.go | 19 +++++++++++ go/go.mod | 3 ++ go/texttest_fixture.go | 26 +++++++------- 7 files changed, 97 insertions(+), 88 deletions(-) delete mode 100644 go/gilded-rose.go delete mode 100644 go/gilded-rose_test.go create mode 100644 go/gildedrose/gildedrose.go create mode 100644 go/gildedrose/gildedrose_test.go create mode 100644 go/go.mod diff --git a/go/README.md b/go/README.md index e22e3776..7b017964 100644 --- a/go/README.md +++ b/go/README.md @@ -3,19 +3,19 @@ - Run : ```shell -go run texttest_fixture.go gilded-rose.go +go run texttest_fixture.go [; 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 ``` \ No newline at end of file diff --git a/go/gilded-rose.go b/go/gilded-rose.go deleted file mode 100644 index 57d2f189..00000000 --- a/go/gilded-rose.go +++ /dev/null @@ -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 - } - } - } - } - -} diff --git a/go/gilded-rose_test.go b/go/gilded-rose_test.go deleted file mode 100644 index 24d64bdd..00000000 --- a/go/gilded-rose_test.go +++ /dev/null @@ -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) - } -} diff --git a/go/gildedrose/gildedrose.go b/go/gildedrose/gildedrose.go new file mode 100644 index 00000000..e0f17e12 --- /dev/null +++ b/go/gildedrose/gildedrose.go @@ -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 + } + } + } + } + +} diff --git a/go/gildedrose/gildedrose_test.go b/go/gildedrose/gildedrose_test.go new file mode 100644 index 00000000..ec1bf49b --- /dev/null +++ b/go/gildedrose/gildedrose_test.go @@ -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) + } +} diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 00000000..00f9da4e --- /dev/null +++ b/go/go.mod @@ -0,0 +1,3 @@ +module github.com/emilybache/gildedrose-refactoring-kata + +go 1.18 diff --git a/go/texttest_fixture.go b/go/texttest_fixture.go index a5b47a77..5c965064 100644 --- a/go/texttest_fixture.go +++ b/go/texttest_fixture.go @@ -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) } }