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

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

Issue 2771453003: Format all tests. (Closed)
Patch Set: Format files Created 3 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
OLDNEW
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2015, 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 secure random generator does not systematically generates 5 // Test that the secure random generator does not systematically generates
6 // duplicates. Note that this test is flaky by definition, since duplicates 6 // duplicates. Note that this test is flaky by definition, since duplicates
7 // can occur. They should be extremely rare, though. 7 // can occur. They should be extremely rare, though.
8 8
9 // Library tag to allow Dartium to run the test. 9 // Library tag to allow Dartium to run the test.
10 library random_secure; 10 library random_secure;
(...skipping 10 matching lines...) Expand all
21 var intVal1 = rng1.nextInt(max); 21 var intVal1 = rng1.nextInt(max);
22 if (max > (1 << 28)) { 22 if (max > (1 << 28)) {
23 Expect.isFalse(results.contains(intVal0)); 23 Expect.isFalse(results.contains(intVal0));
24 results.add(intVal0); 24 results.add(intVal0);
25 Expect.isFalse(results.contains(intVal1)); 25 Expect.isFalse(results.contains(intVal1));
26 results.add(intVal1); 26 results.add(intVal1);
27 } 27 }
28 }; 28 };
29 results = []; 29 results = [];
30 rng0 = new Random.secure(); 30 rng0 = new Random.secure();
31 for(var i = 0; i <= 32; i++) { 31 for (var i = 0; i <= 32; i++) {
32 rng1 = new Random.secure(); 32 rng1 = new Random.secure();
33 checkInt(pow(2, 32)); 33 checkInt(pow(2, 32));
34 checkInt(pow(2, 32 - i)); 34 checkInt(pow(2, 32 - i));
35 checkInt(1000000000); 35 checkInt(1000000000);
36 } 36 }
37 var checkDouble = () { 37 var checkDouble = () {
38 var doubleVal0 = rng0.nextDouble(); 38 var doubleVal0 = rng0.nextDouble();
39 var doubleVal1 = rng1.nextDouble(); 39 var doubleVal1 = rng1.nextDouble();
40 Expect.isFalse(results.contains(doubleVal0)); 40 Expect.isFalse(results.contains(doubleVal0));
41 results.add(doubleVal0); 41 results.add(doubleVal0);
42 Expect.isFalse(results.contains(doubleVal1)); 42 Expect.isFalse(results.contains(doubleVal1));
43 results.add(doubleVal1); 43 results.add(doubleVal1);
44 }; 44 };
45 results = []; 45 results = [];
46 rng0 = new Random.secure(); 46 rng0 = new Random.secure();
47 for(var i = 0; i < 32; i++) { 47 for (var i = 0; i < 32; i++) {
48 rng1 = new Random.secure(); 48 rng1 = new Random.secure();
49 checkDouble(); 49 checkDouble();
50 } 50 }
51 var cnt0 = 0; 51 var cnt0 = 0;
52 var cnt1 = 0; 52 var cnt1 = 0;
53 rng0 = new Random.secure(); 53 rng0 = new Random.secure();
54 for(var i = 0; i < 32; i++) { 54 for (var i = 0; i < 32; i++) {
55 rng1 = new Random.secure(); 55 rng1 = new Random.secure();
56 cnt0 += rng0.nextBool() ? 1 : 0; 56 cnt0 += rng0.nextBool() ? 1 : 0;
57 cnt1 += rng1.nextBool() ? 1 : 0; 57 cnt1 += rng1.nextBool() ? 1 : 0;
58 } 58 }
59 Expect.isTrue((cnt0 > 0) && (cnt0 < 32)); 59 Expect.isTrue((cnt0 > 0) && (cnt0 < 32));
60 Expect.isTrue((cnt1 > 0) && (cnt1 < 32)); 60 Expect.isTrue((cnt1 > 0) && (cnt1 < 32));
61 } 61 }
62
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698