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

Unified Diff: packages/usage/test/uuid_test.dart

Issue 1400473008: Roll Observatory packages and add a roll script (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: 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
« no previous file with comments | « packages/usage/test/usage_test.dart ('k') | packages/usage/test/web.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: packages/usage/test/uuid_test.dart
diff --git a/packages/usage/test/uuid_test.dart b/packages/usage/test/uuid_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cdde2b6a050ad7ddc7fbc462753395adb1288429
--- /dev/null
+++ b/packages/usage/test/uuid_test.dart
@@ -0,0 +1,71 @@
+// Copyright (c) 2014, 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 usage.uuid_test;
+
+import 'package:unittest/unittest.dart';
+import 'package:usage/src/uuid.dart';
+
+void defineTests() {
+ group('uuid', () {
+ // xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx
+ test('simple', () {
+ Uuid uuid = new Uuid();
+ String result = uuid.generateV4();
+ expect(result.length, 36);
+ expect(result[8], '-');
+ expect(result[13], '-');
+ expect(result[18], '-');
+ expect(result[23], '-');
+ });
+
+ test('can parse', () {
+ Uuid uuid = new Uuid();
+ String result = uuid.generateV4();
+ expect(int.parse(result.substring(0, 8), radix: 16), isNotNull);
+ expect(int.parse(result.substring(9, 13), radix: 16), isNotNull);
+ expect(int.parse(result.substring(14, 18), radix: 16), isNotNull);
+ expect(int.parse(result.substring(19, 23), radix: 16), isNotNull);
+ expect(int.parse(result.substring(24, 36), radix: 16), isNotNull);
+ });
+
+ test('special bits', () {
+ Uuid uuid = new Uuid();
+ String result = uuid.generateV4();
+ expect(result[14], '4');
+ expect(result[19].toLowerCase(), isIn('89ab'));
+
+ result = uuid.generateV4();
+ expect(result[19].toLowerCase(), isIn('89ab'));
+
+ result = uuid.generateV4();
+ expect(result[19].toLowerCase(), isIn('89ab'));
+ });
+
+ test('is pretty random', () {
+ Set set = new Set();
+
+ Uuid uuid = new Uuid();
+ for (int i = 0; i < 64; i++) {
+ String val = uuid.generateV4();
+ expect(set, isNot(contains(val)));
+ set.add(val);
+ }
+
+ uuid = new Uuid();
+ for (int i = 0; i < 64; i++) {
+ String val = uuid.generateV4();
+ expect(set, isNot(contains(val)));
+ set.add(val);
+ }
+
+ uuid = new Uuid();
+ for (int i = 0; i < 64; i++) {
+ String val = uuid.generateV4();
+ expect(set, isNot(contains(val)));
+ set.add(val);
+ }
+ });
+ });
+}
« no previous file with comments | « packages/usage/test/usage_test.dart ('k') | packages/usage/test/web.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698