-
Notifications
You must be signed in to change notification settings - Fork 0
/
deck_test.go
49 lines (42 loc) · 1.06 KB
/
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
46
47
48
49
package main
import (
"os"
"testing"
)
func TestNewDeck_HasFiftyTwoCards(t *testing.T) {
d := newDeck()
if len(d) != 52 {
t.Errorf("Expected deck length of 52, but got %d", len(d))
}
}
func TestNewDeck_FirstCard_IsAceOfSpades(t *testing.T) {
d := newDeck()
firstCard := d[0]
if firstCard != "Ace of Spades" {
t.Errorf("Expected the first card to be Ace of Spades, but got %v", firstCard)
}
}
func TestNewDeck_LastCard_IsAceOfSpades(t *testing.T) {
d := newDeck()
lastCard := d[len(d)-1]
if lastCard != "King of Clubs" {
t.Errorf("Expected the last card to be King of Clubs, but got %v", lastCard)
}
}
func cleanUpSaveTestFile() {
testFileName := "_testingDeck.csv"
_, err := os.OpenFile(testFileName, 0, 0666)
if err == nil {
os.Remove(testFileName)
}
}
func TestSaveToDeck_NewDeck(t *testing.T) {
cleanUpSaveTestFile()
deck := newDeck()
deck.saveToFile("_testingDeck")
loadedDeck := loadDeckFromFile("_testingDeck.csv")
if len(loadedDeck) != 52 {
t.Errorf("Expted 52 cards in the deck, but got %d", len(loadedDeck))
}
cleanUpSaveTestFile()
}