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

Unified Diff: packages/quiver/test/iterables/enumerate_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
Index: packages/quiver/test/iterables/enumerate_test.dart
diff --git a/packages/quiver/test/iterables/enumerate_test.dart b/packages/quiver/test/iterables/enumerate_test.dart
new file mode 100644
index 0000000000000000000000000000000000000000..cc8704766653cb19345ece973840e97ce4743de1
--- /dev/null
+++ b/packages/quiver/test/iterables/enumerate_test.dart
@@ -0,0 +1,86 @@
+// Copyright 2013 Google Inc. All Rights Reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+
+library quiver.iterables.enumerate_test;
+
+import 'package:test/test.dart';
+import 'package:quiver/iterables.dart';
+
+main() {
+ group('enumerate', () {
+ test("should add indices to its argument", () {
+ var e = enumerate(['a', 'b', 'c']);
+ expect(e.map((v) => v.index), [0, 1, 2]);
+ expect(e.map((v) => v.value), ['a', 'b', 'c']);
+ });
+
+ test("should return an empty iterable given an empty iterable", () {
+ expect(enumerate([]), []);
+ });
+
+ test("should add indices to its argument", () {
+ var e = enumerate(['a', 'b', 'c']);
+ expect(e.map((v) => v.index), [0, 1, 2]);
+ expect(e.map((v) => v.index), [ 0, 1, 2 ],
+ reason: 'should enumerate to the same values a second time');
+ });
+
+ test("first", () {
+ var e = enumerate(['a', 'b', 'c']);
+ expect(e.first.value, 'a');
+ expect(e.first.index, 0);
+ expect(e.first.value, 'a');
+ });
+
+ test("last", () {
+ var e = enumerate(['a', 'b', 'c']);
+ expect(e.last.value, 'c');
+ expect(e.last.index, 2);
+ expect(e.last.value, 'c');
+ });
+
+ test("single", () {
+ var e = enumerate(['a']);
+ expect(e.single.value, 'a');
+ expect(e.single.index, 0);
+ expect(e.single.value, 'a');
+
+ expect(() => enumerate([1, 2]).single, throws);
+ });
+
+ test("length", () {
+ expect(enumerate([7, 8, 9]).length, 3);
+ });
+
+ test("elementAt", () {
+ var list = ['a', 'b', 'c'];
+ var e = enumerate(list);
+ for (int i = 2; i >= 0; i--) {
+ expect(e.elementAt(i).value, list[i]);
+ expect(e.elementAt(i).index, i);
+ }
+ });
+
+ test("equals and hashcode", () {
+ var list = ['a', 'b', 'c'];
+ var e1 = enumerate(list);
+ var e2 = enumerate(list);
+ for (int i = 0; i < 2; i++) {
+ expect(e1.elementAt(i), e2.elementAt(i));
+ expect(e1.elementAt(i).hashCode, e1.elementAt(i).hashCode);
+ expect(identical(e1.elementAt(i), e2.elementAt(i)), isFalse);
+ }
+ });
+ });
+}
« no previous file with comments | « packages/quiver/test/iterables/cycle_test.dart ('k') | packages/quiver/test/iterables/generating_iterable_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698