Why the compiler shows that the function newDeck() is undeclared in deck_test.go knowing that it's already declared in deck.go and it's working well? If you could help me that will be great thank you.
deck.go
package main
import (
"fmt"
"strings"
)
type deck []string
func (d deck) print() {
for i, card := range d {
fmt.Println(i, card)
}
}
func newDeck() deck {
cards := deck{}
cardSuits := []string{"Spades", "Diamonds", "Hearts", "Clubs"}
cardValue := []string{"Ace", "Two", "Three", "Four"}
for _, suit := range cardSuits {
for _, value := range cardValue {
cards = append(cards, suit+" of "+value)
}
}
return cards
}
deck_test.go
package main
import (
"testing"
)
func TestNewDeck(t *testing.T) {
d := newDeck()
if len(d) != 16 {
t.Error("Expected deck length of 16, but got", len(d))
}
}
Aucun commentaire:
Enregistrer un commentaire