-
Notifications
You must be signed in to change notification settings - Fork 0
/
blackjack_test.go
65 lines (56 loc) · 1.35 KB
/
blackjack_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package gotesting_test
import (
. "github.com/ebonet/gotesting"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/onsi/ginkgo/extensions/table"
"fmt"
)
var _ = Describe("Blackjack", func() {
Describe("Scoring Hand", func() {
Context("with empty hand", func() {
It("Should return 0", func() {
Expect(ComputeScore("")).To(Equal(0))
})
})
Context("with hand A2", func() {
It("Should return 13", func() {
Expect(ComputeScore("A2")).To(Equal(13))
})
})
})
DescribeTable("Scoring a hand",
func(hand string, expected int) {
Expect(ComputeScore(hand)).To(Equal(expected))
},
Entry("2","2", 2),
Entry("3","3", 3),
Entry("J","J", 10),
Entry("A","A", 11),
Entry("AJ","AJ", 21),
Entry("A345","A345", 23),
Entry("Invalid Char","/345≈", 0), // Invalid character
Entry("Empty Hand", "", 0), // Empty hand
)
Describe("Testing for blackjack", func() {
contexts := []struct {
Hand string
ExpectedResult bool
}{
{"AJ", true},
{"JA", true},
{"A4", false},
{"J2", false},
{"2", false},
{"AJ5", false},
}
for _, ctx := range contexts {
ctx := ctx //gotcha!
Context("With hand"+ctx.Hand, func(){
It(fmt.Sprintf("Should return %b", ctx.ExpectedResult), func() {
Expect(CheckIfBlackjack(ctx.Hand)).To(Equal(ctx.ExpectedResult))
})
})
}
})
})