Skip to content

Commit 1600ae0

Browse files
authored
Merge pull request #16524 from huonw/random-fixes-4.2-2018-04-30
[4.2-04-30-2018] Two small tweaks to Random test.
2 parents 5b7d10b + 57f7046 commit 1600ae0

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

validation-test/stdlib/Random.swift

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ func floatingPointRangeTest<T: BinaryFloatingPoint>(_ type: T.Type)
128128
RandomTests.test("random floating points in ranges") {
129129
floatingPointRangeTest(Float.self)
130130
floatingPointRangeTest(Double.self)
131+
#if !os(Windows) && (arch(i386) || arch(x86_64))
131132
floatingPointRangeTest(Float80.self)
133+
#endif
132134
}
133135

134136
// Random Elements from collection
@@ -233,13 +235,18 @@ RandomTests.test("different random number generators") {
233235
func chi2Test(_ samples: [Double]) -> Bool {
234236
precondition(samples.count == 50, "confidence interval requires 50 samples")
235237
let expected = samples.reduce(0, +) / Double(samples.count)
236-
let cvLow = 23.983 // 0.1% with a degree of freedom of (50 - 1)
237-
let cvHigh = 85.351 // 99.9% with a degree of freedom of (50 - 1)
238+
// Right tail for 0.0001% (1e-6) with a degree of freedom of (50 -
239+
// 1). With hundreds of builds a day, this has to be very low to not get too
240+
// many spurious failures, but obvious problems should still be detected
241+
// (e.g. an off-by-one that means samples[0] == 0 will result in chi2 =
242+
// (0-expected)**2/expected + ... > expected, so as long as we've generated
243+
// more than samples.count * cvHigh (~5500) values, we'll catch it).
244+
let cvHigh = 111.1
238245
let chi2 = samples.map {
239246
(($0 - expected) * ($0 - expected)) / expected
240247
}.reduce(0, +)
241248

242-
if chi2 < cvLow || chi2 > cvHigh {
249+
if chi2 > cvHigh {
243250
return false
244251
}else {
245252
return true

0 commit comments

Comments
 (0)