-
Notifications
You must be signed in to change notification settings - Fork 0
/
phrase_test.go
62 lines (49 loc) · 1.53 KB
/
phrase_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
package main
import . "gopkg.in/check.v1"
var _ = Suite(&PhraseTestSuite{})
type PhraseTestSuite struct{}
func (s *PhraseTestSuite) TestEvaluate(c *C) {
equation := " \t\t 6 "
value, err := Evaluate([]byte(equation))
c.Check(err, IsNil)
c.Check(value, Equals, 6)
equation = "- 6"
value, err = Evaluate([]byte(equation))
c.Check(err, IsNil)
c.Check(value, Equals, -6)
equation = "6 - -4"
value, err = Evaluate([]byte(equation))
c.Check(err, IsNil)
c.Check(value, Equals, 6 - -4)
equation = "6---4"
value, err = Evaluate([]byte(equation))
c.Check(IsSyntaxError(err), Equals, true)
c.Check(value, Equals, 0)
equation = "6+4-"
value, err = Evaluate([]byte(equation))
c.Check(IsSyntaxError(err), Equals, true)
c.Check(value, Equals, 0)
equation = "6++4"
value, err = Evaluate([]byte(equation))
c.Check(IsSyntaxError(err), Equals, true)
c.Check(value, Equals, 0)
equation = "d6"
value, err = Evaluate([]byte(equation))
c.Check(err, IsNil)
c.Check(value >= 1 && value <= 6, Equals, true)
c.Logf("Rolled a d6 and got a %d", value)
equation = "10d6"
value, err = Evaluate([]byte(equation))
c.Check(err, IsNil)
c.Check(value >= 10 && value <= 60, Equals, true)
c.Logf("Rolled a 10d6 and got a %d", value)
equation = "(10 + 5)*4"
value, err = Evaluate([]byte(equation))
c.Check(err, IsNil)
c.Check(value, Equals, (10+5)*4)
equation = "10d5 + 7(1d4-1)"
value, err = Evaluate([]byte(equation))
c.Check(err, IsNil)
c.Check(value >= 10 && value <= 71, Equals, true)
c.Logf("Rolled a 10d5+7(1d4-1) and got a %d", value)
}