-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgameState_test.go
More file actions
36 lines (30 loc) · 1004 Bytes
/
gameState_test.go
File metadata and controls
36 lines (30 loc) · 1004 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
36
package main
import "testing"
func TestCalculateWinner(t *testing.T) {
gs := gameState{dealer: player{score: 21}, player: player{score: 21}}
winner := gs.calculateWinner()
if winner == "Player" {
t.Errorf("Ties should go to the dealer")
}
gs = gameState{dealer: player{score: 16}, player: player{score: 22}}
winner = gs.calculateWinner()
if winner == "Player" {
t.Errorf("Scores over 21 should not win")
}
gs = gameState{dealer: player{score: 16}, player: player{score: 20}}
winner = gs.calculateWinner()
if winner == "Dealer" {
t.Errorf("Closest Score should win")
}
gs = gameState{dealer: player{score: 23}, player: player{score: 15}}
winner = gs.calculateWinner()
if winner == "Dealer" {
t.Errorf("Closest Score should win")
}
// natural win
gs = gameState{dealer: player{score: 20, hand: deck{card{}, card{}}}, player: player{score: 21, hand: deck{card{}, card{}}}}
winner = gs.calculateWinner()
if winner == "Dealer" {
t.Errorf("Natural Win goes to player")
}
}