| OLD | NEW |
| 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.dart"); | 9 #library("pi_test.dart"); |
| 10 | 10 |
| (...skipping 10 matching lines...) Expand all Loading... |
| 21 var y = prng.nextDouble(); | 21 var y = prng.nextDouble(); |
| 22 if ((x*x) + (y*y) < 1.0) { | 22 if ((x*x) + (y*y) < 1.0) { |
| 23 inside++; | 23 inside++; |
| 24 } else { | 24 } else { |
| 25 outside++; | 25 outside++; |
| 26 } | 26 } |
| 27 } | 27 } |
| 28 // Mmmmh, Pie! | 28 // Mmmmh, Pie! |
| 29 var pie = 4.0 * (inside/(inside + outside)); | 29 var pie = 4.0 * (inside/(inside + outside)); |
| 30 print("$pie"); | 30 print("$pie"); |
| 31 Expect.isTrue((3.14 < pie) && (pie < 3.15)); | 31 Expect.isTrue(((PI - 0.009) < pie) && (pie < (PI + 0.009))); |
| 32 } | 32 } |
| OLD | NEW |