-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathuniform_test.go
executable file
·71 lines (66 loc) · 1.76 KB
/
uniform_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
package prob
import (
"math"
"testing"
)
//Test at http://keisan.casio.com/exec/system/1180573224
func Test_Uniform(t *testing.T) {
examples := []distributionTest{
distributionTest{
dist: Uniform{0.0, 1.0},
mean: 0.5,
variance: 1.0/12.0,
stdDev: math.Sqrt(1.0/12.0),
relStdDev: math.Sqrt(1.0/12.0) * 2.0,
skewness: 0.0,
kurtosis: -6.0/5.0,
pdf: []inOut{
inOut{ in: -1.0, out: 0.0 },
inOut{ in: 2.0, out: 0.0 },
inOut{ in: 0.5, out: 1.0 },
inOut{ in: 0.25, out: 1.0 },
},
cdf: []inOut{
inOut{ in: -1.0, out: 0.0 },
inOut{ in: 2.0, out: 1.0 },
inOut{ in: 0.5, out: 0.5 },
inOut{ in: 0.25, out: 0.25 },
},
},
distributionTest{
dist: Uniform{420.0, 666.0},
mean: 543.0,
variance: 5043.0,
stdDev: math.Sqrt(5043.0),
relStdDev: math.Sqrt(5043.0) / 543.0,
skewness: 0.0,
kurtosis: -6.0/5.0,
pdf: []inOut{
inOut{ in: 350.0, out: 0.0 },
inOut{ in: 700.0, out: 0.0 },
inOut{ in: 444.0, out: 1.0 / 246.0 },
inOut{ in: 555.0, out: 1.0 / 246.0 },
},
cdf: []inOut{
inOut{ in: 350.0, out: 0.0 },
inOut{ in: 700.0, out: 1.0 },
inOut{ in: 444.0, out: 0.0975609756097561 },
inOut{ in: 555.0, out: 0.5487804878048781 },
},
},
}
if err := testValues(examples); err != nil {
t.Fatal(err)
}
if err := testValues(examples); err != nil {
t.Fatal(err)
}
sample := Uniform{0.0, 10.0}
if err := testSamples(sample); err != nil {
t.Fatal(err)
}
}
func Benchmark_Uniform(b *testing.B) {
dist := Uniform{0.0, 10.0}
runBenchmark(b, dist)
}