-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfluky_integer_test.go
67 lines (58 loc) · 1.88 KB
/
fluky_integer_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
package fluky
import (
src "github.com/Pencroff/fluky/source"
"github.com/stretchr/testify/assert"
"math/rand"
"testing"
"time"
)
func TestFluky_Integer_NoOptions(t *testing.T) {
mRng := new(RngMock)
mRng.On("Int63").Return(int64(1<<63 - 1)).Times(1)
mRng.On("Int63").Return(int64(1 << 62)).Times(1)
mRng.On("Int63").Return(int64(0)).Times(1)
mRng.On("Int63").Return(int64(1)).Times(1)
f := NewFluky(mRng)
assert.Equal(t, 4611686018427387903, f.Integer())
assert.Equal(t, 0, f.Integer())
assert.Equal(t, -4611686018427387904, f.Integer())
assert.Equal(t, -4611686018427387903, f.Integer())
mRng.AssertExpectations(t)
}
func TestFluky_Integer_WithOptions(t *testing.T) {
mRng := new(RngMock)
mRng.On("Int63").Return(int64(1<<63 - 1)).Times(1)
mRng.On("Int63").Return(int64(1 << 62)).Times(1)
mRng.On("Int63").Return(int64(0)).Times(1)
mRng.On("Int63").Return(int64(1)).Times(1)
mRng.On("Int63").Return(int64(7351)).Times(1)
f := NewFluky(mRng)
assert.Equal(t, 75, f.Integer(WithIntRange(-100, 100)))
assert.Equal(t, -12, f.Integer(WithIntRange(-100, 100)))
assert.Equal(t, -100, f.Integer(WithIntRange(-100, 100)))
assert.Equal(t, -99, f.Integer(WithIntRange(-100, 100)))
assert.Equal(t, 15, f.Integer(WithIntRange(-100, 100)))
assert.Equal(t, 5, f.Integer(WithIntRange(5, 5)))
mRng.AssertExpectations(t)
}
func TestFluky_Integer_IncorrectInput(t *testing.T) {
mRng := new(RngMock)
mRng.On("Int63").Return(int64(1))
f := NewFluky(mRng)
assert.Equal(t, 11, f.Integer(WithIntRange(10, -10)))
assert.Equal(t, 1, f.Integer(WithIntRange(0, -10)))
mRng.AssertExpectations(t)
}
func TestFluky_Integer_WithRand(t *testing.T) {
s := src.NewSplitMix64Source(time.Now().UnixNano())
r := rand.New(s)
f := NewFluky(r)
n := 10000
min := 256
max := 512
for i := 0; i < n; i++ {
v := f.Integer(WithIntRange(min, max))
assert.GreaterOrEqual(t, v, min)
assert.LessOrEqual(t, v, max)
}
}