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

Side by Side Diff: packages/quiver_iterables/test/merge_test.dart

Issue 2119523002: Added full js & js_util packages (Closed) Base URL: git@github.com:dart-lang/observatory_pub_packages.git@master
Patch Set: Created 4 years, 5 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 2013 Google Inc. All Rights Reserved. 1 // Copyright 2013 Google Inc. All Rights Reserved.
2 // 2 //
3 // Licensed under the Apache License, Version 2.0 (the "License"); 3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License. 4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at 5 // You may obtain a copy of the License at
6 // 6 //
7 // http://www.apache.org/licenses/LICENSE-2.0 7 // http://www.apache.org/licenses/LICENSE-2.0
8 // 8 //
9 // Unless required by applicable law or agreed to in writing, software 9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS, 10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and 12 // See the License for the specific language governing permissions and
13 // limitations under the License. 13 // limitations under the License.
14 14
15 library quiver.iterables.merge_test; 15 library quiver.iterables.merge_test;
16 16
17 import 'package:test/test.dart'; 17 import 'package:test/test.dart';
18 import 'package:quiver/iterables.dart'; 18 import 'package:quiver_iterables/iterables.dart';
19 19
20 main() { 20 main() {
21 group('merge', () { 21 group('merge', () {
22 test("should merge no iterables into empty iterable", () { 22 test("should merge no iterables into empty iterable", () {
23 expect(merge([]), []); 23 expect(merge([]), []);
24 }); 24 });
25 25
26 test("should merge empty iterables into empty iterable", () { 26 test("should merge empty iterables into empty iterable", () {
27 expect(merge([[]]), []); 27 expect(merge([[]]), []);
28 expect(merge([[], []]), []); 28 expect(merge([[], []]), []);
29 expect(merge([[], [], []]), []); 29 expect(merge([[], [], []]), []);
30 for (int i = 4; i <= 10; i++) { 30 for (int i = 4; i <= 10; i++) {
31 expect(merge(new List.filled(i, const [])), []); 31 expect(merge(new List.filled(i, const [])), []);
32 } 32 }
33 }); 33 });
34 34
35 test("should merge single-element iterables", () { 35 test("should merge single-element iterables", () {
36 expect(merge([['a'], ['b']]), ['a', 'b']); 36 expect(
37 merge([
38 ['a'],
39 ['b']
40 ]),
41 ['a', 'b']);
37 }); 42 });
38 43
39 test("should output the union of elements in both iterables", () { 44 test("should output the union of elements in both iterables", () {
40 var a = ['a', 'b', 'c']; 45 var a = ['a', 'b', 'c'];
41 expect(merge([a, a]), ['a', 'a', 'b', 'b', 'c', 'c']); 46 expect(merge([a, a]), ['a', 'a', 'b', 'b', 'c', 'c']);
42 }); 47 });
43 48
44 test("should honor the comparator", () { 49 test("should honor the comparator", () {
45 var a = ['c', 'b', 'a']; 50 var a = ['c', 'b', 'a'];
46 expect(merge([a, a], (x, y) => -x.compareTo(y)), 51 expect(merge([a, a], (x, y) => -x.compareTo(y)),
47 [ 'c', 'c', 'b', 'b', 'a', 'a' ]); 52 ['c', 'c', 'b', 'b', 'a', 'a']);
48 }); 53 });
49 54
50 test("should merge empty iterables with non-empty ones", () { 55 test("should merge empty iterables with non-empty ones", () {
51 var a = ['a', 'b', 'c']; 56 var a = ['a', 'b', 'c'];
52 expect(merge([a, []]), ['a', 'b', 'c']); 57 expect(merge([a, []]), ['a', 'b', 'c']);
53 expect(merge([[], a]), ['a', 'b', 'c']); 58 expect(merge([[], a]), ['a', 'b', 'c']);
54 }); 59 });
55 60
56 test("should throw on null elements", () { 61 test("should throw on null elements", () {
57 var a = ['a', null, 'c']; 62 var a = ['a', null, 'c'];
(...skipping 13 matching lines...) Expand all
71 var b = <String>['c', 'd']; 76 var b = <String>['c', 'd'];
72 expect(max(a).compareTo(min(b)) < 0, isTrue); // test the test 77 expect(max(a).compareTo(min(b)) < 0, isTrue); // test the test
73 expect(merge([a, b]), ['a', 'b', 'c', 'd']); 78 expect(merge([a, b]), ['a', 'b', 'c', 'd']);
74 }); 79 });
75 80
76 test("should handle three-way zig-zag case", () { 81 test("should handle three-way zig-zag case", () {
77 var a = ['a', 'd', 'g', 'j']; 82 var a = ['a', 'd', 'g', 'j'];
78 var b = ['b', 'e', 'h', 'k']; 83 var b = ['b', 'e', 'h', 'k'];
79 var c = ['c', 'f', 'i', 'l']; 84 var c = ['c', 'f', 'i', 'l'];
80 var expected = [ 85 var expected = [
81 'a', 'b', 'c', 86 'a',
82 'd', 'e', 'f', 87 'b',
83 'g', 'h', 'i', 88 'c',
84 'j', 'k', 'l' 89 'd',
90 'e',
91 'f',
92 'g',
93 'h',
94 'i',
95 'j',
96 'k',
97 'l'
85 ]; 98 ];
86 expect(merge([a, b, c]), expected); 99 expect(merge([a, b, c]), expected);
87 expect(merge([a, c, b]), expected); 100 expect(merge([a, c, b]), expected);
88 expect(merge([b, a, c]), expected); 101 expect(merge([b, a, c]), expected);
89 expect(merge([b, c, a]), expected); 102 expect(merge([b, c, a]), expected);
90 expect(merge([c, a, b]), expected); 103 expect(merge([c, a, b]), expected);
91 expect(merge([c, b, a]), expected); 104 expect(merge([c, b, a]), expected);
92 }); 105 });
93 }); 106 });
94 } 107 }
OLDNEW
« no previous file with comments | « packages/quiver_iterables/test/generating_iterable_test.dart ('k') | packages/quiver_iterables/test/min_max_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698