You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
assertTrue(samplesOutliers <= acceptedOutliers, "Statistical test failed: too many outliers. This may indicate an issue with the normal distribution generator but could also be due to random chance.")
73
+
val sampleMean = sampleSum / toDouble(numSamples)
74
+
val sampleVariance = (sampleSumSq / toDouble(numSamples)) - (sampleMean * sampleMean)
75
+
val sampleStdDev = sqrt(sampleVariance)
76
+
assertTrue(abs(sampleMean - mu) < 0.2, "Statistical test failed: sample mean deviates significantly from expected mean. This may indicate an issue with the normal distribution generator but could also be due to random chance.")
77
+
assertTrue(abs(sampleStdDev - sigma) < 0.2, "Statistical test failed: sample standard deviation deviates significantly from expected standard deviation. This may indicate an issue with the normal distribution generator but could also be due to random chance.")
78
+
}
79
+
80
+
test("read exponential distributed values") {
81
+
val lambda = 1.0
82
+
val numSamples = 100000
83
+
val acceptedOutliers = 100 // Allow some outliers due to randomness
84
+
var samplesRead = 0
85
+
var samplesOutliers = 0
86
+
var sampleSum = 0.0
87
+
88
+
exponentialDistributedPull(lambda) {
89
+
while (samplesRead < numSamples) {
90
+
try {
91
+
val v = do read[Double]()
92
+
93
+
assertTrue(v >= 0.0, "Exponential distributed value should be non-negative")
assertTrue(samplesOutliers <= acceptedOutliers, "Statistical test failed: too many outliers. This may indicate an issue with the exponential distribution generator but could also be due to random chance.")
104
+
val sampleMean = sampleSum / toDouble(numSamples)
105
+
val expectedMean = 1.0 / lambda
106
+
assertTrue(abs(sampleMean - expectedMean) < 0.2, "Statistical test failed: sample mean deviates significantly from expected mean. This may indicate an issue with the exponential distribution generator but could also be due to random chance.")
107
+
}
108
+
109
+
test("read uniform distributed values") {
110
+
val a = -5.0
111
+
val b = 5.0
112
+
val numSamples = 100000
113
+
val acceptedOutliers = 100 // Allow some outliers due to randomness
assertTrue(samplesOutliers <= acceptedOutliers, "Statistical test failed: too many outliers. This may indicate an issue with the uniform distribution generator but could also be due to random chance.")
133
+
val sampleMean = sampleSum / toDouble(numSamples)
134
+
val expectedMean = (a + b) / 2.0
135
+
assertTrue(abs(sampleMean - expectedMean) < 0.2, "Statistical test failed: sample mean deviates significantly from expected mean. This may indicate an issue with the uniform distribution generator but could also be due to random chance.")
0 commit comments