-
Notifications
You must be signed in to change notification settings - Fork 1
/
dice_test.go
83 lines (71 loc) · 1.56 KB
/
dice_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
package roll_test
import (
"testing"
"github.com/brittonhayes/roll"
"github.com/stretchr/testify/assert"
)
func TestDice_String(t *testing.T) {
type fields struct {
Min int
Max int
}
tests := []struct {
name string
fields fields
want string
}{
{name: "D6", fields: fields{Min: 1, Max: 6}, want: "d6"},
{name: "D12", fields: fields{Min: 1, Max: 12}, want: "d12"},
{name: "D20", fields: fields{Min: 1, Max: 20}, want: "d20"},
{name: "D100", fields: fields{Min: 1, Max: 100}, want: "d100"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
d := roll.Die{
Min: tt.fields.Min,
Max: tt.fields.Max,
}
assert.Equal(t, tt.want, d.String())
})
}
}
func TestDice_Roll(t *testing.T) {
t.Run("rolled greater than or equal to dice minimum", func(t *testing.T) {
d := &roll.Die{
Min: 1,
Max: 6,
}
got := d.Roll()
assert.GreaterOrEqual(t, got, d.Min)
})
t.Run("rolled less than or equal to dice maximum", func(t *testing.T) {
d := &roll.Die{
Min: 1,
Max: 6,
}
got := d.Roll()
assert.LessOrEqual(t, got, d.Max)
})
}
func TestDice_Validate(t *testing.T) {
dice := []*roll.Die{
{Min: 1, Max: 6},
{Min: 1, Max: 20},
{Min: 1, Max: 100},
{Min: 1, Max: 12},
{Min: 1, Max: 8},
}
t.Run("Dice are valid", func(t *testing.T) {
for _, d := range dice {
err := d.Validate()
assert.NoError(t, err)
}
})
}
func TestNewD6(t *testing.T) {
t.Run("New D6 has min 1 and max 6", func(t *testing.T) {
want := &roll.Die{Min: 1, Max: 6}
got := roll.NewD6()
assert.Equal(t, want, got)
})
}