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

Unified Diff: tests/lib/math/random_secure_test.dart

Issue 1398453004: Add a 'secure' constructor to Random in dart:math returning a cryptographically (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: fix comments Created 5 years, 2 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 side-by-side diff with in-line comments
Download patch
« sdk/lib/math/random.dart ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: tests/lib/math/random_secure_test.dart
diff --git a/tests/lib/math/random_secure_test.dart b/tests/lib/math/random_secure_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..22bb48cef3ba704d17ebc6e60ffe2bdb6f471e3f
--- /dev/null
+++ b/tests/lib/math/random_secure_test.dart
@@ -0,0 +1,23 @@
+// Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file
+// for details. All rights reserved. Use of this source code is governed by a
+// BSD-style license that can be found in the LICENSE file.
+
+// Library tag to allow Dartium to run the test.
+library random_secure;
+
+import "package:expect/expect.dart";
+import 'dart:math';
+
+main() {
+ var results = [];
+ for(var i = 0; i < 10; i++) {
+ var rng = new Random.secure();
+ var intVal = rng.nextInt(10000000);
+ Expect.isFalse(results.contains(intVal));
Lasse Reichstein Nielsen 2015/10/14 11:08:45 This is not a test of randomness. It's just a flak
regis 2015/10/14 20:22:36 Acknowledged. I just copied code from random_big_t
+ results.add(intVal);
+ var doubleVal = rng.nextDouble();
+ Expect.isFalse(results.contains(doubleVal));
Lasse Reichstein Nielsen 2015/10/14 11:08:46 I wouldn't check doubles in the same loop as the i
regis 2015/10/14 20:22:36 Done.
+ results.add(doubleVal);
+ rng.nextBool();
+ }
Lasse Reichstein Nielsen 2015/10/14 11:08:46 Basically, there is no need to make a new test. Us
regis 2015/10/14 20:22:35 One existing test checks that the sequence is dete
+}
« sdk/lib/math/random.dart ('K') | « tests/lib/lib.status ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698