mirror of
https://github.com/emilybache/GildedRose-Refactoring-Kata.git
synced 2025-12-12 04:12:13 +00:00
Go: Extracts texttest_feature.go from main Gilded Rose, write test similar to other languages.
This commit is contained in:
parent
ab83717690
commit
60b2549066
@ -3,7 +3,7 @@
|
|||||||
- Run :
|
- Run :
|
||||||
|
|
||||||
```shell
|
```shell
|
||||||
go run gilded-rose.go
|
go run texttest_feature.go gilded-rose.go
|
||||||
```
|
```
|
||||||
|
|
||||||
- Run tests :
|
- Run tests :
|
||||||
|
|||||||
@ -1,28 +1,11 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import "fmt"
|
|
||||||
|
|
||||||
type Item struct {
|
type Item struct {
|
||||||
name string
|
name string
|
||||||
sellIn, quality int
|
sellIn, quality int
|
||||||
}
|
}
|
||||||
|
|
||||||
var items = []Item{
|
func UpdateQuality(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)
|
|
||||||
GildedRose()
|
|
||||||
}
|
|
||||||
|
|
||||||
func GildedRose() {
|
|
||||||
for i := 0; i < len(items); i++ {
|
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].name != "Aged Brie" && items[i].name != "Backstage passes to a TAFKAL80ETC concert" {
|
||||||
|
|||||||
@ -2,6 +2,14 @@ package main
|
|||||||
|
|
||||||
import "testing"
|
import "testing"
|
||||||
|
|
||||||
func Test_GildedRose(t *testing.T) {
|
func Test_Foo(t *testing.T) {
|
||||||
main()
|
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)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
44
go/texttest_feature.go
Normal file
44
go/texttest_feature.go
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
"strconv"
|
||||||
|
)
|
||||||
|
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
days := 2
|
||||||
|
var err error
|
||||||
|
if len(os.Args) > 1 {
|
||||||
|
days, err = strconv.Atoi(os.Args[1])
|
||||||
|
if err != nil {
|
||||||
|
fmt.Println(err.Error())
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
|
days++
|
||||||
|
}
|
||||||
|
|
||||||
|
for day := 0; day < days; day++ {
|
||||||
|
fmt.Printf("-------- day %d --------\n", day)
|
||||||
|
fmt.Println("name, sellIn, quality")
|
||||||
|
for i := 0; i < len(items); i++ {
|
||||||
|
fmt.Println(items[i])
|
||||||
|
}
|
||||||
|
fmt.Println("")
|
||||||
|
UpdateQuality(items)
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user