-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRngStream_test.go
131 lines (106 loc) · 2.45 KB
/
RngStream_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
package rngstream
import (
"fmt"
"math"
"testing"
)
// Compute (a*s + c) % m. m must be < 2^35. Works also for s, c < 0
// func multModM(a, s, c, m int64) int64 {
func TestMultModM(t *testing.T) {
SetPackageSeed([]uint64{12345, 12345, 12345, 12345, 12345, 12345})
got := multModM(3, 5, 11, 7)
want := float64((3*5 + 11) % 7)
fmt.Printf("TestMultModM: got %v; expected %v\n", got, want)
if got != want {
t.Errorf("got %v, wanted %v", got, want)
}
}
func Test1(t *testing.T) {
SetPackageSeed([]uint64{12345, 12345, 12345, 12345, 12345, 12345})
germe := []uint64{1, 1, 1, 1, 1, 1}
g1 := New("g1")
g2 := New("g2")
g3 := New("g3")
sum := g2.RandU01() + g3.RandU01()
g1.AdvanceState(5, 3)
sum += g1.RandU01()
g1.ResetStartStream()
for i := 0; i < 35; i++ {
g1.AdvanceState(0, 1)
}
sum += g1.RandU01()
g1.ResetStartStream()
sumi := 0
for i := 0; i < 35; i++ {
sumi += g1.RandInt(1, 10)
}
sum += float64(sumi) / 100.0
sum3 := 0.0
for i := 0; i < 100; i++ {
sum3 += g3.RandU01()
}
sum += sum3 / 10.0
g3.ResetStartStream()
for i := 1; i <= 5; i++ {
sum += g3.RandU01()
}
for i := 0; i < 4; i++ {
g3.ResetNextSubstream()
}
for i := 0; i < 5; i++ {
sum += g3.RandU01()
}
g3.ResetStartSubstream()
for i := 0; i < 5; i++ {
sum += g3.RandU01()
}
g2.ResetNextSubstream()
sum3 = 0.0
for i := 1; i <= 100000; i++ {
sum3 += g2.RandU01()
}
sum += sum3 / 10000.0
g3.SetAntithetic(true)
sum3 = 0.0
for i := 1; i <= 100000; i++ {
sum3 += g3.RandU01()
}
sum += sum3 / 10000.0
SetPackageSeed(germe)
gar := make([]*RngStream, 4)
gar[0] = New("Poisson")
gar[1] = New("Laplace")
gar[2] = New("Galois")
gar[3] = New("Cantor")
for i := 0; i < 4; i++ {
sum += gar[i].RandU01()
}
gar[2].AdvanceState(-127, 0)
sum += gar[2].RandU01()
gar[2].ResetNextSubstream()
gar[2].SetIncreasedPrecis(true)
sum3 = 0.0
for i := 0; i < 100000; i++ {
sum3 += gar[2].RandU01()
}
sum += sum3 / 10000.0
gar[2].SetAntithetic(true)
sum3 = 0.0
for i := 0; i < 100000; i++ {
sum3 += gar[2].RandU01()
}
sum += sum3 / 10000.0
gar[2].SetAntithetic(false)
gar[2].SetIncreasedPrecis(false)
for i := 0; i < 4; i++ {
sum += gar[i].RandU01()
}
fmt.Printf("-----------------------------------------------------\n")
fmt.Printf("This test program should print the number 39.697547 \n\n")
fmt.Printf("Actual test result = %.6f", sum)
if math.Abs(sum-39.697547) < 1e-6 {
fmt.Printf("\t ... ok\n\n")
} else {
t.Error("no match")
}
}