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

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

Issue 10389150: - Add a math library. Currently it mostly matches the Math class in dart:core. (Closed) Base URL: http://dart.googlecode.com/svn/branches/bleeding_edge/dart/
Patch Set: Created 8 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 unified diff | Download patch | Annotate | Revision Log
« tests/lib/lib.status ('K') | « tests/lib/math/low_test.dart ('k') | 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
(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.dart");
10
11 #import("dart:math");
12
13 void main() {
14 var prng = new Random();
15 var outside = 0;
16 var inside = 0;
17 for (var i = 0; i < 600000; i++) {
18 var x = prng.nextDouble();
19 var y = prng.nextDouble();
20 if ((x*x) + (y*y) < 1.0) {
21 inside++;
22 } else {
23 outside++;
24 }
25 }
26 // Mmmmh, Pie!
27 var pie = 4.0 * (inside/(inside + outside));
28 print("$pie");
29 Expect.isTrue((3.14 < pie) && (pie < 3.15));
30 }
OLDNEW
« tests/lib/lib.status ('K') | « tests/lib/math/low_test.dart ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698