-
Notifications
You must be signed in to change notification settings - Fork 13
/
versus_test.go
93 lines (66 loc) · 1.95 KB
/
versus_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
package dice_test
import (
. "github.com/justinian/dice"
. "gopkg.in/check.v1"
)
/* =============================================================================
* vs dice test suite
*/
type vsSuite struct {
}
/*
func (s *DiceSuite) SetUpSuite(c *C) {
}
func (s *DiceSuite) SetUpTest(c *C) {
}
*/
var _ = Suite(&vsSuite{})
/* =============================================================================
* vs dice test cases
*/
func (s *vsSuite) TestBounds(c *C) {
var roller VsRoller
r, err := roller.Roll([]string{"100d2v2", "100", "2", "", "2"})
res := r.(VsResult)
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 *vsSuite) TestExplode(c *C) {
var roller VsRoller
r, err := roller.Roll([]string{"3d6ev1", "5", "4", "e", "1"})
res := r.(VsResult)
c.Assert(err, IsNil)
c.Assert(res.String(), Matches, "5 \\[\\d+ \\d+ \\d+ \\d+ \\d+\\]")
}
func (s *vsSuite) TestInvalidNumber(c *C) {
var roller VsRoller
r, err := roller.Roll([]string{"1d1v1", "1", "1", "", "1"})
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, "Sides must be 2 or more")
c.Assert(r, IsNil)
r, err = roller.Roll([]string{"0d2v1", "0", "2", "", "1"})
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, "Count must be 1 or more")
c.Assert(r, IsNil)
}
func (s *vsSuite) TestNumTooBig(c *C) {
var roller VsRoller
//const bigNum = int(^uint(0)>>1) + 1
const bigNum = "9223372036854775808"
r, err := roller.Roll([]string{"1d2v1", bigNum, "2", "", "1"})
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, "*value out of range")
c.Assert(r, IsNil)
r, err = roller.Roll([]string{"1d2v1", "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{"1d2v1", "1", "2", "", bigNum})
c.Assert(err, NotNil)
c.Assert(err.Error(), Matches, "*value out of range")
c.Assert(r, IsNil)
}