Skip to content

Instantly share code, notes, and snippets.

@percybolmer
Last active December 21, 2021 09:01
Show Gist options
  • Save percybolmer/33c74401052948d5f7189ecd097f1a10 to your computer and use it in GitHub Desktop.
Save percybolmer/33c74401052948d5f7189ecd097f1a10 to your computer and use it in GitHub Desktop.
A CO Pilot generated table test
// table driven unit tests for Deck.Draw
func TestDeck_Draw(t *testing.T) {
type args struct {
n int
}
tests := []struct {
name string
d Deck
args args
want []Card
}{
{
name: "Draw 5 cards from a deck",
d: NewDeck(),
args: args{n: 5},
want: []Card{
{
Suit: "Spades",
Rank: "Ace",
},
{
Suit: "Spades",
Rank: "Two",
},
{
Suit: "Spades",
Rank: "Three",
},
{
Suit: "Spades",
Rank: "Four",
},
{
Suit: "Spades",
Rank: "Five",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.d.Draw(tt.args.n); !reflect.DeepEqual(got, tt.want) {
t.Errorf("Deck.Draw() = %v, want %v", got, tt.want)
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment