| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 a coin toss with Random.nextBool() is fair. | 5 // Test that a coin toss with Random.nextBool() is fair. |
| 6 | 6 |
| 7 // Library tag to allow Dartium to run the test. | 7 // Library tag to allow Dartium to run the test. |
| 8 library random_test; | 8 library random_test; |
| 9 | 9 |
| 10 import "package:expect/expect.dart"; | 10 import "package:expect/expect.dart"; |
| (...skipping 29 matching lines...) Expand all Loading... |
| 40 Expect.equals( 7976427, rnd.nextInt(1 << ++i)); | 40 Expect.equals( 7976427, rnd.nextInt(1 << ++i)); |
| 41 Expect.equals( 31792146, rnd.nextInt(1 << ++i)); | 41 Expect.equals( 31792146, rnd.nextInt(1 << ++i)); |
| 42 Expect.equals( 35563210, rnd.nextInt(1 << ++i)); | 42 Expect.equals( 35563210, rnd.nextInt(1 << ++i)); |
| 43 Expect.equals( 113261265, rnd.nextInt(1 << ++i)); | 43 Expect.equals( 113261265, rnd.nextInt(1 << ++i)); |
| 44 Expect.equals( 205117298, rnd.nextInt(1 << ++i)); | 44 Expect.equals( 205117298, rnd.nextInt(1 << ++i)); |
| 45 Expect.equals( 447729735, rnd.nextInt(1 << ++i)); | 45 Expect.equals( 447729735, rnd.nextInt(1 << ++i)); |
| 46 Expect.equals(1072507596, rnd.nextInt(1 << ++i)); | 46 Expect.equals(1072507596, rnd.nextInt(1 << ++i)); |
| 47 Expect.equals(2134030067, rnd.nextInt(1 << ++i)); | 47 Expect.equals(2134030067, rnd.nextInt(1 << ++i)); |
| 48 Expect.equals(721180690, rnd.nextInt(1 << ++i)); | 48 Expect.equals(721180690, rnd.nextInt(1 << ++i)); |
| 49 Expect.equals(32, i); | 49 Expect.equals(32, i); |
| 50 // If max is too large expect an ArgumentError. | 50 // If max is too large expect an ArgumentError. |
| 51 Expect.throws(() => rnd.nextInt((1 << i)+1), (e) => e is ArgumentError); | 51 Expect.throws(() => rnd.nextInt((1 << i)+1), (e) => e is ArgumentError); |
| 52 |
| 53 rnd = new Random(6790); |
| 54 Expect.approxEquals(0.7360144236, rnd.nextDouble()); |
| 55 Expect.approxEquals(0.3292339731, rnd.nextDouble()); |
| 56 Expect.approxEquals(0.3489622548, rnd.nextDouble()); |
| 57 Expect.approxEquals(0.9815975892, rnd.nextDouble()); |
| 52 } | 58 } |
| OLD | NEW |