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

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

Issue 12212016: Remove Expect from core library. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add deprecation comment for ExpectException and revert one test. Created 7 years, 8 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/min_max_test.dart ('k') | tests/lib/math/random_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 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 'dart:math'; 12 import 'dart:math';
12 13
13 void main() { 14 void main() {
14 var seed = new Random().nextInt(1<<16); 15 var seed = new Random().nextInt(1<<16);
15 print("pi_test seed: $seed"); 16 print("pi_test seed: $seed");
16 var prng = new Random(seed); 17 var prng = new Random(seed);
17 var outside = 0; 18 var outside = 0;
18 var inside = 0; 19 var inside = 0;
19 for (var i = 0; i < 600000; i++) { 20 for (var i = 0; i < 600000; i++) {
20 var x = prng.nextDouble(); 21 var x = prng.nextDouble();
21 var y = prng.nextDouble(); 22 var y = prng.nextDouble();
22 if ((x*x) + (y*y) < 1.0) { 23 if ((x*x) + (y*y) < 1.0) {
23 inside++; 24 inside++;
24 } else { 25 } else {
25 outside++; 26 outside++;
26 } 27 }
27 } 28 }
28 // Mmmmh, Pie! 29 // Mmmmh, Pie!
29 var pie = 4.0 * (inside/(inside + outside)); 30 var pie = 4.0 * (inside/(inside + outside));
30 print("$pie"); 31 print("$pie");
31 Expect.isTrue(((PI - 0.009) < pie) && (pie < (PI + 0.009))); 32 Expect.isTrue(((PI - 0.009) < pie) && (pie < (PI + 0.009)));
32 } 33 }
OLDNEW
« no previous file with comments | « tests/lib/math/min_max_test.dart ('k') | tests/lib/math/random_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698