From f61db113b6b070093c27d10b0f21acf0afb83a7e Mon Sep 17 00:00:00 2001 From: Looly Date: Sat, 18 Oct 2025 20:13:11 +0800 Subject: [PATCH] add test --- .../v7/core/collection/CollUtilTest.java | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/hutool-core/src/test/java/cn/hutool/v7/core/collection/CollUtilTest.java b/hutool-core/src/test/java/cn/hutool/v7/core/collection/CollUtilTest.java index 1c0140ff3..3e662b98b 100644 --- a/hutool-core/src/test/java/cn/hutool/v7/core/collection/CollUtilTest.java +++ b/hutool-core/src/test/java/cn/hutool/v7/core/collection/CollUtilTest.java @@ -993,6 +993,31 @@ public class CollUtilTest { assertEquals(ListUtil.of("aa", "bb", "cc", "dd"), extract); } + @Test + public void zipTest2() { + // 1. 正常情况测试 + List list1 = ListUtil.of("a", "b", "c"); + List list2 = ListUtil.of(1, 2, 3); + List result = CollUtil.zip(list1, list2, (s, i) -> s + i); + assertEquals(ListUtil.of("a1", "b2", "c3"), result); + + // 2. 空集合测试 + List emptyList = ListUtil.of(); + List emptyResult = CollUtil.zip(emptyList, list2, (s, i) -> s + i); + assertTrue(emptyResult.isEmpty()); + + // 3. 不同大小集合测试(以较小集合为准) + List longerList = ListUtil.of(1, 2, 3, 4, 5); + List sizedResult = CollUtil.zip(list1, longerList, (s, i) -> s + i); + assertEquals(3, sizedResult.size()); + assertEquals("a1", sizedResult.get(0)); + + // 4. 自定义zipper函数测试 + List list3 = ListUtil.of(1.1, 2.2, 3.3); + List customResult = CollUtil.zip(list2, list3, (i, d) -> String.format("%d-%.1f", i, d)); + assertEquals(ListUtil.of("1-1.1", "2-2.2", "3-3.3"), customResult); + } + @Test public void createTest() { final Collection collection = CollUtil.create(Collections.emptyList().getClass());