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

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

Issue 2995343002: Migrated test block 216 to Dart 2.0. (Closed)
Patch Set: Migrated min_max_test to Dart 2.0 Created 3 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
« no previous file with comments | « tests/lib_strong/math/min_max_test.dart ('k') | tests/lib_strong/math/point_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
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // Test that the default PRNG does converge towards Pi when doing a Monte Carlo
6 // simulation.
7
8 // Library tag to allow Dartium to run the test.
9 library pi_test;
10
11 import "package:expect/expect.dart";
12 import 'dart:math';
13
14 var known_bad_seeds = const [50051, 55597, 59208];
15
16 void main([args]) {
17 // Select a seed either from the argument passed in or
18 // otherwise a random seed.
19 var seed = -1;
20 if ((args != null) && (args.length > 0)) {
21 seed = int.parse(args[0]);
22 } else {
23 var seed_prng = new Random();
24 while (seed == -1) {
25 seed = seed_prng.nextInt(1 << 16);
26 if (known_bad_seeds.contains(seed)) {
27 // Reset seed and try again.
28 seed = -1;
29 }
30 }
31 }
32
33 // Setup the PRNG for the Monte Carlo simulation.
34 print("pi_test seed: $seed");
35 var prng = new Random(seed);
36
37 var outside = 0;
38 var inside = 0;
39 for (var i = 0; i < 600000; i++) {
40 var x = prng.nextDouble();
41 var y = prng.nextDouble();
42 if ((x * x) + (y * y) < 1.0) {
43 inside++;
44 } else {
45 outside++;
46 }
47 }
48 // Mmmmh, Pie!
49 var pie = 4.0 * (inside / (inside + outside));
50 print("$pie");
51 Expect.isTrue(((PI - 0.009) < pie) && (pie < (PI + 0.009)));
52 }
OLDNEW
« no previous file with comments | « tests/lib_strong/math/min_max_test.dart ('k') | tests/lib_strong/math/point_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698