We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0f63df6 commit 8b5c8f7Copy full SHA for 8b5c8f7
spec/ruby/core/array/sample_spec.rb
@@ -6,12 +6,23 @@
6
ary = [0, 1, 2, 3]
7
3.times do |i|
8
counts = [0, 0, 0, 0]
9
- 4000.times do
10
- counts[ary.sample(3)[i]] += 1
+ iters = 4000
+ expected = iters / counts.size
11
+ iters.times do
12
+ x = ary.sample(3)[i]
13
+ counts[x] += 1
14
end
15
+ chi_squared = 0.0
16
counts.each do |count|
- (800..1200).should include(count)
17
+ chi_squared += (((count - expected) ** 2) * 1.0 / expected)
18
19
+
20
+ # Chi squared critical values for tests with 4 degrees of freedom
21
+ # Values obtained from NIST Engineering Statistic Handbook at
22
+ # https://www.itl.nist.gov/div898/handbook/eda/section3/eda3674.htm
23
24
+ chi_squared.should <= 9.488
25
+ chi_squared.should >= 0.711
26
27
28
0 commit comments