Anonymous user
Verify distribution uniformity/Naive: Difference between revisions
Verify distribution uniformity/Naive (view source)
Revision as of 22:22, 19 December 2011
, 12 years agoUpdated D code
m (→{{header|Go}}: library changes) |
(Updated D code) |
||
Line 213:
<lang d>import std.math: abs;
import std.string: format;
import std.stdio:
import std.algorithm: sort;
/**
Bin the answers to fn() and check bin counts are within
+/- delta % of repeats/bincount.
*/
void distCheck(TF)(in TF func, in int
int[int]
immutable double target =
immutable int deltaCount = cast(int)(delta / 100.0 * target);
foreach (k, count;
if (abs(target - count) >= deltaCount)
throw new Exception(format(
"distribution potentially skewed for '%s':
k, count));
foreach (k; counts.keys.sort())
writeln(k, " ", counts[k]);
writeln();
}</lang>
|