Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(122)

Unified Diff: tests/lib/math/coin_test.dart

Issue 15356003: - Extend the coin test for slightly different scenarios. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « runtime/lib/math_patch.dart ('k') | tests/lib/math/random_test.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/math/coin_test.dart
===================================================================
--- tests/lib/math/coin_test.dart (revision 23308)
+++ tests/lib/math/coin_test.dart (working copy)
@@ -27,4 +27,36 @@
"Tails: $tails\n"
"Ratio: ${heads/tails}\n");
Expect.approxEquals(1.0, heads/tails, 0.1);
+
+ heads = 0;
+ tails = 0;
+ for (var i = 0; i < 10000; i++) {
+ rnd = new Random(i);
+ if (rnd.nextBool()) {
+ heads++;
+ } else {
+ tails++;
+ }
+ }
+ print("Heads: $heads\n"
+ "Tails: $tails\n"
+ "Ratio: ${heads/tails}\n");
+ Expect.approxEquals(1.0, heads/tails, 0.1);
+
+ // A sequence of newly allocated Random number generators should have fair
+ // initial tosses.
+ heads = 0;
+ tails = 0;
+ for (var i = 0; i < 10000; i++) {
+ rnd = new Random();
+ if (rnd.nextBool()) {
+ heads++;
+ } else {
+ tails++;
+ }
+ }
+ print("Heads: $heads\n"
+ "Tails: $tails\n"
+ "Ratio: ${heads/tails}\n");
+ Expect.approxEquals(1.0, heads/tails, 0.1);
}
« no previous file with comments | « runtime/lib/math_patch.dart ('k') | tests/lib/math/random_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698