-
Notifications
You must be signed in to change notification settings - Fork 13
/
std_test.go
124 lines (88 loc) · 2.55 KB
/
std_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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
package dice_test
import (
"testing"
. "github.com/justinian/dice"
. "gopkg.in/check.v1"
)
/* =============================================================================
* Std dice test suite
*/
func TestStd(t *testing.T) { TestingT(t) }
type stdSuite struct {
}
/*
func (s *DiceSuite) SetUpSuite(c *C) {
}
func (s *DiceSuite) SetUpTest(c *C) {
}
*/
var _ = Suite(&stdSuite{})
/* =============================================================================
* Std dice test cases
*/
func (s *stdSuite) TestBounds(c *C) {
var roller StdRoller
r, err := roller.Roll([]string{"100d2", "100", "2", "", "", "", ""})
res := r.(StdResult)
c.Assert(err, IsNil)
for _, v := range res.Rolls {
if v <= 0 || v > 2 {
c.Errorf("Rolled out of bounds on a d2: %d", v)
}
}
}
func (s *stdSuite) TestCount(c *C) {
var roller StdRoller
r, err := roller.Roll([]string{"100d2", "100", "2", "", "", "", ""})
res := r.(StdResult)
c.Assert(err, IsNil)
c.Assert(res.Rolls, HasLen, 100)
}
func (s *stdSuite) TestAdd(c *C) {
var roller StdRoller
r, err := roller.Roll([]string{"1d1+13", "1", "1", "", "", "", "13"})
res := r.(StdResult)
c.Assert(err, IsNil)
c.Assert(res.Rolls, HasLen, 1)
c.Assert(res.Total, Equals, 14)
}
func (s *stdSuite) TestKeep(c *C) {
var roller StdRoller
r, err := roller.Roll([]string{"10d6", "10", "6", "k2", "k", "2", ""})
res := r.(StdResult)
c.Assert(err, IsNil)
c.Assert(res.Rolls, HasLen, 2)
c.Assert(res.Dropped, HasLen, 8)
}
func (s *stdSuite) TestDrop(c *C) {
var roller StdRoller
r, err := roller.Roll([]string{"10d6", "10", "6", "d2", "d", "2", ""})
res := r.(StdResult)
c.Assert(err, IsNil)
c.Assert(res.Rolls, HasLen, 8)
c.Assert(res.Dropped, HasLen, 2)
}
func (s *stdSuite) TestBonus(c *C) {
var roller StdRoller
r, err := roller.Roll([]string{"1d1+1", "1", "1", "", "", "", "1"})
res := r.(StdResult)
c.Assert(err, IsNil)
c.Assert(res.String(), Equals, "2 [1]")
}
func (s *stdSuite) TestNumTooBig(c *C) {
var roller StdRoller
//const bigNum = int(^uint(0)>>1) + 1
const bigNum = "9223372036854775808"
r, err := roller.Roll([]string{"1d1+1", bigNum, "1", "", "", "", "1"})
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, "*value out of range")
c.Assert(r, IsNil)
r, err = roller.Roll([]string{"1d1+1", "1", bigNum, "", "", "", "1"})
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, "*value out of range")
c.Assert(r, IsNil)
r, err = roller.Roll([]string{"1d1+1", "1", "1", "", "", "", bigNum})
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, "*value out of range")
c.Assert(r, IsNil)
}