-
-
Notifications
You must be signed in to change notification settings - Fork 263
/
game_test.go
106 lines (87 loc) · 1.8 KB
/
game_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
package gofakeit
import (
"fmt"
"testing"
)
func ExampleGamertag() {
Seed(11)
fmt.Println(Gamertag())
// Output: TurkeyThinker
}
func ExampleFaker_Gamertag() {
f := New(11)
fmt.Println(f.Gamertag())
// Output: TurkeyThinker
}
func TestGamertag(t *testing.T) {
for i := 0; i < 100; i++ {
g := Gamertag()
if g == "" {
t.Errorf("Gamertag() returned empty string")
}
}
}
func BenchmarkGamertag(b *testing.B) {
for i := 0; i < b.N; i++ {
Gamertag()
}
}
func ExampleDice() {
Seed(11)
fmt.Println(Dice(1, []uint{6}))
// Output: [6]
}
func ExampleFaker_Dice() {
f := New(11)
fmt.Println(f.Dice(1, []uint{6}))
// Output: [6]
}
func TestDice(t *testing.T) {
for i := 0; i < 100; i++ {
// put together random number of dice and sides
numDice := uint(Number(1, 10))
sides := make([]uint, numDice)
for i := 0; i < int(numDice); i++ {
sides[i] = uint(Number(1, 10))
}
g := Dice(numDice, sides)
if len(g) == 0 {
t.Errorf("Dice() returned empty uint array")
}
// Make sure the length of the array is the same as the number of dice
if len(g) != int(numDice) {
t.Errorf("Dice() returned wrong length array")
}
}
}
func TestDiceNoSides(t *testing.T) {
for i := 0; i < 100; i++ {
g := Dice(1, []uint{})
if len(g) != 1 {
t.Errorf("Dice() returned non-empty array")
}
// Make sure g[1] is betwwen 1 and 6
if g[0] < 1 || g[0] > 6 {
t.Errorf("Dice() returned wrong number")
}
}
}
func TestDiceOneSide(t *testing.T) {
for i := 0; i < 100; i++ {
g := Dice(10, []uint{1})
if len(g) != 10 {
t.Errorf("Dice() returned non 10 value array")
}
// Make sure all g values are 1
for _, v := range g {
if v != 1 {
t.Errorf("Dice() returned wrong number")
}
}
}
}
func BenchmarkDice(b *testing.B) {
for i := 0; i < b.N; i++ {
Dice(1, []uint{6})
}
}