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

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

Issue 581263003: Fix Dartium tests: (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 6 years, 3 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 | « no previous file | no next file » | 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 converge towards Pi when doing a Monte Carlo 5 // Test that the default PRNG does converge towards Pi when doing a Monte Carlo
6 // simulation. 6 // simulation.
7 7
8 // Library tag to allow Dartium to run the test. 8 // Library tag to allow Dartium to run the test.
9 library pi_test; 9 library pi_test;
10 10
11 import "package:expect/expect.dart"; 11 import "package:expect/expect.dart";
12 import 'dart:math'; 12 import 'dart:math';
13 13
14 var known_bad_seeds = const [ 14 var known_bad_seeds = const [
15 50051, 15 50051,
16 55597, 16 55597,
17 59208 17 59208
18 ]; 18 ];
19 19
20 void main(args) { 20 void main([args]) {
21 // Select a seed either from the argument passed in or 21 // Select a seed either from the argument passed in or
22 // otherwise a random seed. 22 // otherwise a random seed.
23 var seed = -1; 23 var seed = -1;
24 if ((args != null) && (args.length > 0)) { 24 if ((args != null) && (args.length > 0)) {
25 seed = int.parse(args[0]); 25 seed = int.parse(args[0]);
26 } else { 26 } else {
27 var seed_prng = new Random(); 27 var seed_prng = new Random();
28 while (seed == -1) { 28 while (seed == -1) {
29 seed = seed_prng.nextInt(1<<16); 29 seed = seed_prng.nextInt(1<<16);
30 if (known_bad_seeds.contains(seed)) { 30 if (known_bad_seeds.contains(seed)) {
(...skipping 16 matching lines...) Expand all
47 inside++; 47 inside++;
48 } else { 48 } else {
49 outside++; 49 outside++;
50 } 50 }
51 } 51 }
52 // Mmmmh, Pie! 52 // Mmmmh, Pie!
53 var pie = 4.0 * (inside/(inside + outside)); 53 var pie = 4.0 * (inside/(inside + outside));
54 print("$pie"); 54 print("$pie");
55 Expect.isTrue(((PI - 0.009) < pie) && (pie < (PI + 0.009))); 55 Expect.isTrue(((PI - 0.009) < pie) && (pie < (PI + 0.009)));
56 } 56 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698