-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeck_test.go
More file actions
35 lines (25 loc) · 719 Bytes
/
deck_test.go
File metadata and controls
35 lines (25 loc) · 719 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
package cards
import "testing"
import "os"
func TestNewDeck(t *testing.T) {
d := NewDeck()
if len(d) != 52 {
t.Errorf("Expected deck lenght of 52, but got %v", len(d))
}
if d[0] != "Ace of Spades" {
t.Errorf("Expected first card to be Ace of Spades, but got %v", d[0])
}
if d[len(d)-1] != "King of Clubs" {
t.Errorf("Expected last card to be King of Clubs, but got %v", d[len(d)-1])
}
}
func TestSaveToDeckAndNewDeckFromFile(t *testing.T) {
os.Remove("_decktesting")
deck := NewDeck()
deck.SaveToFile("_decktesting")
loadedDeck := NewDeckFromFile("_decktesting")
if len(loadedDeck) != 52 {
t.Errorf("Expected 52 cards in deck, but got %v", len(loadedDeck))
}
os.Remove("_decktesting")
}