OLD | NEW |
| (Empty) |
1 // Copyright 2013 Google Inc. All Rights Reserved. | |
2 // | |
3 // Licensed under the Apache License, Version 2.0 (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 | |
6 // | |
7 // http://www.apache.org/licenses/LICENSE-2.0 | |
8 // | |
9 // Unless required by applicable law or agreed to in writing, software | |
10 // distributed under the License is distributed on an "AS IS" BASIS, | |
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
12 // See the License for the specific language governing permissions and | |
13 // limitations under the License. | |
14 | |
15 library quiver.iterables.merge_test; | |
16 | |
17 import 'package:test/test.dart'; | |
18 import 'package:quiver_iterables/iterables.dart'; | |
19 | |
20 main() { | |
21 group('merge', () { | |
22 test("should merge no iterables into empty iterable", () { | |
23 expect(merge([]), []); | |
24 }); | |
25 | |
26 test("should merge empty iterables into empty iterable", () { | |
27 expect(merge([[]]), []); | |
28 expect(merge([[], []]), []); | |
29 expect(merge([[], [], []]), []); | |
30 for (int i = 4; i <= 10; i++) { | |
31 expect(merge(new List.filled(i, const [])), []); | |
32 } | |
33 }); | |
34 | |
35 test("should merge single-element iterables", () { | |
36 expect( | |
37 merge([ | |
38 ['a'], | |
39 ['b'] | |
40 ]), | |
41 ['a', 'b']); | |
42 }); | |
43 | |
44 test("should output the union of elements in both iterables", () { | |
45 var a = ['a', 'b', 'c']; | |
46 expect(merge([a, a]), ['a', 'a', 'b', 'b', 'c', 'c']); | |
47 }); | |
48 | |
49 test("should honor the comparator", () { | |
50 var a = ['c', 'b', 'a']; | |
51 expect(merge([a, a], (x, y) => -x.compareTo(y)), | |
52 ['c', 'c', 'b', 'b', 'a', 'a']); | |
53 }); | |
54 | |
55 test("should merge empty iterables with non-empty ones", () { | |
56 var a = ['a', 'b', 'c']; | |
57 expect(merge([a, []]), ['a', 'b', 'c']); | |
58 expect(merge([[], a]), ['a', 'b', 'c']); | |
59 }); | |
60 | |
61 test("should throw on null elements", () { | |
62 var a = ['a', null, 'c']; | |
63 var b = ['a', 'b', 'c']; | |
64 expect(() => merge([a, b]).forEach((e) {}), throws); | |
65 expect(() => merge([b, a]).forEach((e) {}), throws); | |
66 }); | |
67 | |
68 test("should handle zig-zag case", () { | |
69 var a = ['a', 'a', 'd', 'f']; | |
70 var b = ['b', 'c', 'g', 'g']; | |
71 expect(merge([a, b]), ['a', 'a', 'b', 'c', 'd', 'f', 'g', 'g']); | |
72 }); | |
73 | |
74 test("should handle max(a) < min(b) case", () { | |
75 var a = <String>['a', 'b']; | |
76 var b = <String>['c', 'd']; | |
77 expect(max(a).compareTo(min(b)) < 0, isTrue); // test the test | |
78 expect(merge([a, b]), ['a', 'b', 'c', 'd']); | |
79 }); | |
80 | |
81 test("should handle three-way zig-zag case", () { | |
82 var a = ['a', 'd', 'g', 'j']; | |
83 var b = ['b', 'e', 'h', 'k']; | |
84 var c = ['c', 'f', 'i', 'l']; | |
85 var expected = [ | |
86 'a', | |
87 'b', | |
88 'c', | |
89 'd', | |
90 'e', | |
91 'f', | |
92 'g', | |
93 'h', | |
94 'i', | |
95 'j', | |
96 'k', | |
97 'l' | |
98 ]; | |
99 expect(merge([a, b, c]), expected); | |
100 expect(merge([a, c, b]), expected); | |
101 expect(merge([b, a, c]), expected); | |
102 expect(merge([b, c, a]), expected); | |
103 expect(merge([c, a, b]), expected); | |
104 expect(merge([c, b, a]), expected); | |
105 }); | |
106 }); | |
107 } | |
OLD | NEW |