| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | |
| 2 // for details. All rights reserved. Use of this source code is governed by a | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import "dart:collection"; | |
| 6 import "package:sequence_zip/iterable_zip.dart"; | |
| 7 import "package:unittest/unittest.dart"; | |
| 8 | |
| 9 /// Iterable like [base] except that it throws when value equals [errorValue]. | |
| 10 Iterable iterError(Iterable base, int errorValue) { | |
| 11 return base.map((x) => x == errorValue ? throw "BAD" : x); | |
| 12 } | |
| 13 | |
| 14 main() { | |
| 15 test("Basic", () { | |
| 16 expect(new IterableZip([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), | |
| 17 equals([[1, 4, 7], [2, 5, 8], [3, 6, 9]])); | |
| 18 }); | |
| 19 | |
| 20 test("Uneven length 1", () { | |
| 21 expect(new IterableZip([[1, 2, 3, 99, 100], [4, 5, 6], [7, 8, 9]]), | |
| 22 equals([[1, 4, 7], [2, 5, 8], [3, 6, 9]])); | |
| 23 }); | |
| 24 | |
| 25 test("Uneven length 2", () { | |
| 26 expect(new IterableZip([[1, 2, 3], [4, 5, 6, 99, 100], [7, 8, 9]]), | |
| 27 equals([[1, 4, 7], [2, 5, 8], [3, 6, 9]])); | |
| 28 }); | |
| 29 | |
| 30 test("Uneven length 3", () { | |
| 31 expect(new IterableZip([[1, 2, 3], [4, 5, 6], [7, 8, 9, 99, 100]]), | |
| 32 equals([[1, 4, 7], [2, 5, 8], [3, 6, 9]])); | |
| 33 }); | |
| 34 | |
| 35 test("Uneven length 3", () { | |
| 36 expect(new IterableZip([[1, 2, 3, 98], [4, 5, 6], [7, 8, 9, 99, 100]]), | |
| 37 equals([[1, 4, 7], [2, 5, 8], [3, 6, 9]])); | |
| 38 }); | |
| 39 | |
| 40 test("Empty 1", () { | |
| 41 expect(new IterableZip([[], [4, 5, 6], [7, 8, 9]]), equals([])); | |
| 42 }); | |
| 43 | |
| 44 test("Empty 2", () { | |
| 45 expect(new IterableZip([[1, 2, 3], [], [7, 8, 9]]), equals([])); | |
| 46 }); | |
| 47 | |
| 48 test("Empty 3", () { | |
| 49 expect(new IterableZip([[1, 2, 3], [4, 5, 6], []]), equals([])); | |
| 50 }); | |
| 51 | |
| 52 test("Empty source", () { | |
| 53 expect(new IterableZip([]), equals([])); | |
| 54 }); | |
| 55 | |
| 56 test("Single Source", () { | |
| 57 expect(new IterableZip([[1, 2, 3]]), equals([[1], [2], [3]])); | |
| 58 }); | |
| 59 | |
| 60 test("Not-lists", () { | |
| 61 // Use other iterables than list literals. | |
| 62 Iterable it1 = [1, 2, 3, 4, 5, 6].where((x) => x < 4); | |
| 63 Set it2 = new LinkedHashSet()..add(4)..add(5)..add(6); | |
| 64 Iterable it3 = (new LinkedHashMap()..[7] = 0 ..[8] = 0 ..[9] = 0).keys; | |
| 65 Iterable<Iterable> allIts = | |
| 66 new Iterable.generate(3, (i) => [it1, it2, it3][i]); | |
| 67 expect(new IterableZip(allIts), | |
| 68 equals([[1, 4, 7], [2, 5, 8], [3, 6, 9]])); | |
| 69 }); | |
| 70 | |
| 71 test("Error 1", () { | |
| 72 expect(() => new IterableZip([iterError([1, 2, 3], 2), | |
| 73 [4, 5, 6], | |
| 74 [7, 8, 9]]).toList(), | |
| 75 throwsA(equals("BAD"))); | |
| 76 }); | |
| 77 | |
| 78 test("Error 2", () { | |
| 79 expect(() => new IterableZip([[1, 2, 3], | |
| 80 iterError([4, 5, 6], 5), | |
| 81 [7, 8, 9]]).toList(), | |
| 82 throwsA(equals("BAD"))); | |
| 83 }); | |
| 84 | |
| 85 test("Error 3", () { | |
| 86 expect(() => new IterableZip([[1, 2, 3], | |
| 87 [4, 5, 6], | |
| 88 iterError([7, 8, 9], 8)]).toList(), | |
| 89 throwsA(equals("BAD"))); | |
| 90 }); | |
| 91 | |
| 92 test("Error at end", () { | |
| 93 expect(() => new IterableZip([[1, 2, 3], | |
| 94 iterError([4, 5, 6], 6), | |
| 95 [7, 8, 9]]).toList(), | |
| 96 throwsA(equals("BAD"))); | |
| 97 }); | |
| 98 | |
| 99 test("Error before first end", () { | |
| 100 expect(() => new IterableZip([iterError([1, 2, 3, 4], 4), | |
| 101 [4, 5, 6], | |
| 102 [7, 8, 9]]).toList(), | |
| 103 throwsA(equals("BAD"))); | |
| 104 }); | |
| 105 | |
| 106 test("Error after first end", () { | |
| 107 expect(new IterableZip([[1, 2, 3], | |
| 108 [4, 5, 6], | |
| 109 iterError([7, 8, 9, 10], 10)]), | |
| 110 equals([[1, 4, 7], [2, 5, 8], [3, 6, 9]])); | |
| 111 }); | |
| 112 } | |
| OLD | NEW |