Verify distribution uniformity/Naive: Difference between revisions

Content added Content deleted
(→‎{{header|Racket}}: naive test replaces better chi-squared test)
(Updated D entry)
Line 331: Line 331:
+/- delta % of repeats/bincount.
+/- delta % of repeats/bincount.
*/
*/
void distCheck(TF)(in TF func, in int nRepeats, in double delta)
void distCheck(TF)(in TF func, in int nRepeats, in double delta) /*@safe*/
if (isCallable!TF) {
if (isCallable!TF) {
int[int] counts;
int[int] counts;
Line 339: Line 339:
immutable int deltaCount = cast(int)(delta / 100.0 * target);
immutable int deltaCount = cast(int)(delta / 100.0 * target);


foreach (k, count; counts)
foreach (immutable k, const count; counts)
if (abs(target - count) >= deltaCount)
if (abs(target - count) >= deltaCount)
throw new Exception(format(
throw new Exception(format(
Line 345: Line 345:
k, count));
k, count));


foreach (k; counts.keys.sort())
foreach (immutable k; counts.keys.sort())
writeln(k, " ", counts[k]);
writeln(k, " ", counts[k]);
writeln;
writeln;