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

Side by Side Diff: tests/lib/math/low_test.dart

Issue 12743005: Revert "Remove Expect from core library." (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Reupload (first upload failed). Created 7 years, 9 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « tests/lib/math/coin_test.dart ('k') | tests/lib/math/math2_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 // Test that the default PRNG does uniformly distribute values when not using 5 // Test that the default PRNG does uniformly distribute values when not using
6 // a power of 2. 6 // a power of 2.
7 7
8 // Library tag to allow Dartium to run the test. 8 // Library tag to allow Dartium to run the test.
9 library low_test; 9 library low_test;
10 10
11 import "package:expect/expect.dart";
12 import 'dart:math'; 11 import 'dart:math';
13 12
14 void main() { 13 void main() {
15 var n = (2 * (1<<32)) ~/ 3; 14 var n = (2 * (1<<32)) ~/ 3;
16 var n2 = n ~/ 2; 15 var n2 = n ~/ 2;
17 16
18 var iterations = 200000; 17 var iterations = 200000;
19 18
20 var seed = new Random().nextInt(1<<16); 19 var seed = new Random().nextInt(1<<16);
21 print("low_test seed: $seed"); 20 print("low_test seed: $seed");
22 var prng = new Random(seed); 21 var prng = new Random(seed);
23 22
24 var low = 0; 23 var low = 0;
25 for (var i = 0; i < iterations; i++) { 24 for (var i = 0; i < iterations; i++) {
26 if (prng.nextInt(n) < n2) { 25 if (prng.nextInt(n) < n2) {
27 low++; 26 low++;
28 } 27 }
29 } 28 }
30 29
31 var diff = (low - (iterations ~/ 2)).abs(); 30 var diff = (low - (iterations ~/ 2)).abs();
32 print("$low, $diff"); 31 print("$low, $diff");
33 Expect.isTrue(diff < (iterations ~/ 20)); 32 Expect.isTrue(diff < (iterations ~/ 20));
34 } 33 }
OLDNEW
« no previous file with comments | « tests/lib/math/coin_test.dart ('k') | tests/lib/math/math2_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698