Skip to content

Commit 4f33d62

Browse files
committed
Add zip test case
1 parent b73e537 commit 4f33d62

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

src/test/java/com/bestvike/linq/enumerable/ZipTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,7 @@ void Zip3_RunOnce() {
662662
void testZip() {
663663
IEnumerable<String> e1 = Linq.of(Arrays.asList("a", "b", "c"));
664664
IEnumerable<String> e2 = Linq.of(Arrays.asList("1", "2", "3"));
665+
IEnumerable<String> e3 = Linq.of(Arrays.asList("h", "i", "j"));
665666

666667
IEnumerable<String> zipped = e1.zip(e2, (v0, v1) -> v0 + v1);
667668
assertEquals(3, zipped.count());
@@ -675,19 +676,37 @@ void testZip() {
675676
assertEquals(Empty + (char) ('1' + i), zipped2.elementAt(i).getItem2());
676677
}
677678

679+
IEnumerable<Tuple3<String, String, String>> zipped3 = e1.zip(e2, e3);
680+
assertEquals(3, zipped3.count());
681+
for (int i = 0; i < 3; i++) {
682+
assertEquals(Empty + (char) ('a' + i), zipped3.elementAt(i).getItem1());
683+
assertEquals(Empty + (char) ('1' + i), zipped3.elementAt(i).getItem2());
684+
assertEquals(Empty + (char) ('h' + i), zipped3.elementAt(i).getItem3());
685+
}
686+
687+
//
678688
IEnumerable<Tuple2<String, String>> source = e1.zip(e2);
679689
try (IEnumerator<Tuple2<String, String>> e = source.enumerator()) {
680690
for (int i = 0; i < 3; i++)
681691
assertTrue(e.moveNext());
682692
assertFalse(e.moveNext());
683693
assertFalse(e.moveNext());
684694
}
695+
696+
IEnumerable<Tuple3<String, String, String>> source2 = e1.zip(e2, e3);
697+
try (IEnumerator<Tuple3<String, String, String>> e = source2.enumerator()) {
698+
for (int i = 0; i < 3; i++)
699+
assertTrue(e.moveNext());
700+
assertFalse(e.moveNext());
701+
assertFalse(e.moveNext());
702+
}
685703
}
686704

687705
@Test
688706
void testZipLengthNotMatch() {
689707
IEnumerable<String> e1 = Linq.of(Arrays.asList("a", "b"));
690708
IEnumerable<String> e2 = Linq.of(Arrays.asList("1", "2", "3"));
709+
IEnumerable<String> e3 = Linq.of(Arrays.asList("h", "i"));
691710

692711
IEnumerable<String> zipped1 = e1.zip(e2, (v0, v1) -> v0 + v1);
693712
assertEquals(2, zipped1.count());
@@ -699,6 +718,7 @@ void testZipLengthNotMatch() {
699718
for (int i = 0; i < 2; i++)
700719
assertEquals(Empty + (char) ('1' + i) + (char) ('a' + i), zipped2.elementAt(i));
701720

721+
//
702722
IEnumerable<Tuple2<String, String>> zipped3 = e1.zip(e2);
703723
assertEquals(2, zipped3.count());
704724
for (int i = 0; i < 2; i++) {
@@ -712,5 +732,22 @@ void testZipLengthNotMatch() {
712732
assertEquals(Empty + (char) ('1' + i), zipped4.elementAt(i).getItem1());
713733
assertEquals(Empty + (char) ('a' + i), zipped4.elementAt(i).getItem2());
714734
}
735+
736+
//
737+
IEnumerable<Tuple3<String, String, String>> zipped5 = e1.zip(e2, e3);
738+
assertEquals(2, zipped5.count());
739+
for (int i = 0; i < 2; i++) {
740+
assertEquals(Empty + (char) ('a' + i), zipped5.elementAt(i).getItem1());
741+
assertEquals(Empty + (char) ('1' + i), zipped5.elementAt(i).getItem2());
742+
assertEquals(Empty + (char) ('h' + i), zipped5.elementAt(i).getItem3());
743+
}
744+
745+
IEnumerable<Tuple3<String, String, String>> zipped6 = e2.zip(e1, e3);
746+
assertEquals(2, zipped6.count());
747+
for (int i = 0; i < 2; i++) {
748+
assertEquals(Empty + (char) ('1' + i), zipped6.elementAt(i).getItem1());
749+
assertEquals(Empty + (char) ('a' + i), zipped6.elementAt(i).getItem2());
750+
assertEquals(Empty + (char) ('h' + i), zipped6.elementAt(i).getItem3());
751+
}
715752
}
716753
}

0 commit comments

Comments
 (0)