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 rnd.nextInt with a seed generates the same sequence each time. | 5 // Test that rnd.nextInt with a seed generates the same sequence each time. |
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 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
49 Expect.equals( 9680425, rnd.nextInt(i *= 2)); | 49 Expect.equals( 9680425, rnd.nextInt(i *= 2)); |
50 Expect.equals( 28460171, rnd.nextInt(i *= 2)); | 50 Expect.equals( 28460171, rnd.nextInt(i *= 2)); |
51 Expect.equals( 49481738, rnd.nextInt(i *= 2)); | 51 Expect.equals( 49481738, rnd.nextInt(i *= 2)); |
52 Expect.equals( 9878974, rnd.nextInt(i *= 2)); | 52 Expect.equals( 9878974, rnd.nextInt(i *= 2)); |
53 Expect.equals( 132552472, rnd.nextInt(i *= 2)); | 53 Expect.equals( 132552472, rnd.nextInt(i *= 2)); |
54 Expect.equals( 210267283, rnd.nextInt(i *= 2)); | 54 Expect.equals( 210267283, rnd.nextInt(i *= 2)); |
55 Expect.equals( 125422442, rnd.nextInt(i *= 2)); | 55 Expect.equals( 125422442, rnd.nextInt(i *= 2)); |
56 Expect.equals( 226275094, rnd.nextInt(i *= 2)); | 56 Expect.equals( 226275094, rnd.nextInt(i *= 2)); |
57 Expect.equals(1639629168, rnd.nextInt(i *= 2)); | 57 Expect.equals(1639629168, rnd.nextInt(i *= 2)); |
58 Expect.equals(0x100000000, i); | 58 Expect.equals(0x100000000, i); |
59 Expect.equals( 1552504971, rnd.nextInt(i)); | |
Lasse Reichstein Nielsen
2015/10/15 09:32:33
Why? We already called with that value of max abov
regis
2015/10/15 17:12:02
Aargh. Left over from debugging. Reverted.
I was
| |
59 // If max is too large expect an ArgumentError. | 60 // If max is too large expect an ArgumentError. |
60 Expect.throws(() => rnd.nextInt(i + 1), (e) => e is ArgumentError); | 61 Expect.throws(() => rnd.nextInt(i + 1), (e) => e is ArgumentError); |
61 | 62 |
62 rnd = new Random(6790); | 63 rnd = new Random(6790); |
63 Expect.approxEquals(0.1202733131, rnd.nextDouble()); | 64 Expect.approxEquals(0.1202733131, rnd.nextDouble()); |
64 Expect.approxEquals(0.5554054805, rnd.nextDouble()); | 65 Expect.approxEquals(0.5554054805, rnd.nextDouble()); |
65 Expect.approxEquals(0.0385160727, rnd.nextDouble()); | 66 Expect.approxEquals(0.0385160727, rnd.nextDouble()); |
66 Expect.approxEquals(0.2836345217, rnd.nextDouble()); | 67 Expect.approxEquals(0.2836345217, rnd.nextDouble()); |
67 } | 68 } |
68 | 69 |
(...skipping 23 matching lines...) Expand all Loading... | |
92 ]; | 93 ]; |
93 for (var i = 0, m = 1; i < 75; i++) { | 94 for (var i = 0, m = 1; i < 75; i++) { |
94 Expect.equals(expectations[i], new Random(rawSeed * m).nextInt(65536)); | 95 Expect.equals(expectations[i], new Random(rawSeed * m).nextInt(65536)); |
95 Expect.equals(negative_seed_expectations[i], | 96 Expect.equals(negative_seed_expectations[i], |
96 new Random(rawSeed * -m).nextInt(65536)); | 97 new Random(rawSeed * -m).nextInt(65536)); |
97 m *= 2; | 98 m *= 2; |
98 } | 99 } |
99 // And test zero seed too. | 100 // And test zero seed too. |
100 Expect.equals(21391, new Random(0).nextInt(65536)); | 101 Expect.equals(21391, new Random(0).nextInt(65536)); |
101 } | 102 } |
OLD | NEW |