-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck_test.go
45 lines (33 loc) · 986 Bytes
/
deck_test.go
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
36
37
38
39
40
41
42
43
44
45
package main
import (
"os"
"testing"
)
func TestNewDeck(t *testing.T) {
d := newDeck()
if len(d) != 16 {
t.Errorf("Expected deck length of 16, but got %v", len(d))
}
if d[0] != "Ace of Spades" {
t.Errorf("Expected first card of Ace of Spades, but got %v", d[0])
}
if d[len(d)-1] != "Four of Clubs" {
t.Errorf("Expected last card of Four of Clubs, but got %v", d[len(d)-1])
}
}
func TestSaveToDeckAndNewDeckTestFromFile(t *testing.T) {
os.Remove("_decktesting")
deck := newDeck()
deck.saveToFile("_decktesting")
loadedDeck := newDeckFromFile("_decktesting")
if len(loadedDeck) != 16 {
t.Errorf("Expected 16 cards in deck, got %v", len(loadedDeck))
}
if loadedDeck[0] != "Ace of Spades" {
t.Errorf("Expected first card of Ace of Spades, but got %v", loadedDeck[0])
}
if loadedDeck[len(loadedDeck)-1] != "Four of Clubs" {
t.Errorf("Expected last card of Four of Clubs, but got %v", loadedDeck[len(loadedDeck)-1])
}
os.Remove(("_decktesting"))
}