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.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(merge([['a'], ['b']]), ['a', 'b']); |
| 37 }); |
| 38 |
| 39 test("should output the union of elements in both iterables", () { |
| 40 var a = ['a', 'b', 'c']; |
| 41 expect(merge([a, a]), ['a', 'a', 'b', 'b', 'c', 'c']); |
| 42 }); |
| 43 |
| 44 test("should honor the comparator", () { |
| 45 var a = ['c', 'b', 'a']; |
| 46 expect(merge([a, a], (x, y) => -x.compareTo(y)), |
| 47 [ 'c', 'c', 'b', 'b', 'a', 'a' ]); |
| 48 }); |
| 49 |
| 50 test("should merge empty iterables with non-empty ones", () { |
| 51 var a = ['a', 'b', 'c']; |
| 52 expect(merge([a, []]), ['a', 'b', 'c']); |
| 53 expect(merge([[], a]), ['a', 'b', 'c']); |
| 54 }); |
| 55 |
| 56 test("should throw on null elements", () { |
| 57 var a = ['a', null, 'c']; |
| 58 var b = ['a', 'b', 'c']; |
| 59 expect(() => merge([a, b]).forEach((e) {}), throws); |
| 60 expect(() => merge([b, a]).forEach((e) {}), throws); |
| 61 }); |
| 62 |
| 63 test("should handle zig-zag case", () { |
| 64 var a = ['a', 'a', 'd', 'f']; |
| 65 var b = ['b', 'c', 'g', 'g']; |
| 66 expect(merge([a, b]), ['a', 'a', 'b', 'c', 'd', 'f', 'g', 'g']); |
| 67 }); |
| 68 |
| 69 test("should handle max(a) < min(b) case", () { |
| 70 var a = <String>['a', 'b']; |
| 71 var b = <String>['c', 'd']; |
| 72 expect(max(a).compareTo(min(b)) < 0, isTrue); // test the test |
| 73 expect(merge([a, b]), ['a', 'b', 'c', 'd']); |
| 74 }); |
| 75 |
| 76 test("should handle three-way zig-zag case", () { |
| 77 var a = ['a', 'd', 'g', 'j']; |
| 78 var b = ['b', 'e', 'h', 'k']; |
| 79 var c = ['c', 'f', 'i', 'l']; |
| 80 var expected = [ |
| 81 'a', 'b', 'c', |
| 82 'd', 'e', 'f', |
| 83 'g', 'h', 'i', |
| 84 'j', 'k', 'l' |
| 85 ]; |
| 86 expect(merge([a, b, c]), expected); |
| 87 expect(merge([a, c, b]), expected); |
| 88 expect(merge([b, a, c]), expected); |
| 89 expect(merge([b, c, a]), expected); |
| 90 expect(merge([c, a, b]), expected); |
| 91 expect(merge([c, b, a]), expected); |
| 92 }); |
| 93 }); |
| 94 } |
OLD | NEW |