mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -297,17 +297,17 @@ public class CollUtilTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitTest() {
|
||||
public void partitionTest() {
|
||||
final List<Integer> list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<List<Integer>> split = CollUtil.split(list, 3);
|
||||
final List<List<Integer>> split = CollUtil.partition(list, 3);
|
||||
Assert.assertEquals(3, split.size());
|
||||
Assert.assertEquals(3, split.get(0).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void splitTest2() {
|
||||
public void partitionTest2() {
|
||||
final ArrayList<Integer> list = ListUtil.of(1, 2, 3, 4, 5, 6, 7, 8, 9);
|
||||
final List<List<Integer>> split = CollUtil.split(list, Integer.MAX_VALUE);
|
||||
final List<List<Integer>> split = CollUtil.partition(list, Integer.MAX_VALUE);
|
||||
Assert.assertEquals(1, split.size());
|
||||
Assert.assertEquals(9, split.get(0).size());
|
||||
}
|
||||
|
@@ -16,25 +16,25 @@ import java.util.concurrent.CopyOnWriteArrayList;
|
||||
public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void splitTest() {
|
||||
List<List<Object>> lists = ListUtil.split(null, 3);
|
||||
public void partitionTest() {
|
||||
List<List<Object>> lists = ListUtil.partition(null, 3);
|
||||
Assert.assertEquals(ListUtil.empty(), lists);
|
||||
|
||||
lists = ListUtil.split(Arrays.asList(1, 2, 3, 4), 1);
|
||||
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 1);
|
||||
Assert.assertEquals("[[1], [2], [3], [4]]", lists.toString());
|
||||
lists = ListUtil.split(Arrays.asList(1, 2, 3, 4), 2);
|
||||
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 2);
|
||||
Assert.assertEquals("[[1, 2], [3, 4]]", lists.toString());
|
||||
lists = ListUtil.split(Arrays.asList(1, 2, 3, 4), 3);
|
||||
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 3);
|
||||
Assert.assertEquals("[[1, 2, 3], [4]]", lists.toString());
|
||||
lists = ListUtil.split(Arrays.asList(1, 2, 3, 4), 4);
|
||||
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 4);
|
||||
Assert.assertEquals("[[1, 2, 3, 4]]", lists.toString());
|
||||
lists = ListUtil.split(Arrays.asList(1, 2, 3, 4), 5);
|
||||
lists = ListUtil.partition(Arrays.asList(1, 2, 3, 4), 5);
|
||||
Assert.assertEquals("[[1, 2, 3, 4]]", lists.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void splitBenchTest() {
|
||||
public void partitionBenchTest() {
|
||||
final List<String> list = new ArrayList<>();
|
||||
CollUtil.padRight(list, RandomUtil.randomInt(1000_0000, 1_0000_0000), "test");
|
||||
|
||||
@@ -44,11 +44,11 @@ public class ListUtilTest {
|
||||
final StopWatch stopWatch = new StopWatch();
|
||||
|
||||
stopWatch.start("CollUtil#split");
|
||||
final List<List<String>> CollSplitResult = CollUtil.split(list, size);
|
||||
final List<List<String>> CollSplitResult = CollUtil.partition(list, size);
|
||||
stopWatch.stop();
|
||||
|
||||
stopWatch.start("ListUtil#split");
|
||||
final List<List<String>> ListSplitResult = ListUtil.split(list, size);
|
||||
final List<List<String>> ListSplitResult = ListUtil.partition(list, size);
|
||||
stopWatch.stop();
|
||||
|
||||
Assert.assertEquals(CollSplitResult, ListSplitResult);
|
||||
@@ -58,28 +58,28 @@ public class ListUtilTest {
|
||||
|
||||
@Test
|
||||
public void splitAvgTest() {
|
||||
List<List<Object>> lists = ListUtil.splitAvg(null, 3);
|
||||
List<List<Object>> lists = ListUtil.avgPartition(null, 3);
|
||||
Assert.assertEquals(ListUtil.empty(), lists);
|
||||
|
||||
lists = ListUtil.splitAvg(Arrays.asList(1, 2, 3, 4), 1);
|
||||
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 1);
|
||||
Assert.assertEquals("[[1, 2, 3, 4]]", lists.toString());
|
||||
lists = ListUtil.splitAvg(Arrays.asList(1, 2, 3, 4), 2);
|
||||
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 2);
|
||||
Assert.assertEquals("[[1, 2], [3, 4]]", lists.toString());
|
||||
lists = ListUtil.splitAvg(Arrays.asList(1, 2, 3, 4), 3);
|
||||
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 3);
|
||||
Assert.assertEquals("[[1, 2], [3], [4]]", lists.toString());
|
||||
lists = ListUtil.splitAvg(Arrays.asList(1, 2, 3, 4), 4);
|
||||
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 4);
|
||||
Assert.assertEquals("[[1], [2], [3], [4]]", lists.toString());
|
||||
|
||||
lists = ListUtil.splitAvg(Arrays.asList(1, 2, 3), 5);
|
||||
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3), 5);
|
||||
Assert.assertEquals("[[1], [2], [3], [], []]", lists.toString());
|
||||
lists = ListUtil.splitAvg(Arrays.asList(1, 2, 3), 2);
|
||||
lists = ListUtil.avgPartition(Arrays.asList(1, 2, 3), 2);
|
||||
Assert.assertEquals("[[1, 2], [3]]", lists.toString());
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void splitAvgNotZero() {
|
||||
// limit不能小于等于0
|
||||
ListUtil.splitAvg(Arrays.asList(1, 2, 3, 4), 0);
|
||||
ListUtil.avgPartition(Arrays.asList(1, 2, 3, 4), 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -650,7 +650,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
public void testListSplit() {
|
||||
final List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
|
||||
List<List<Integer>> lists = wrap(list).split(2).map(TerminableWrappedStream::toList).toList();
|
||||
Assert.assertEquals(ListUtil.split(list, 2), lists);
|
||||
Assert.assertEquals(ListUtil.partition(list, 2), lists);
|
||||
|
||||
// 指定长度 大于等于 列表长度
|
||||
lists = wrap(list).split(list.size()).map(TerminableWrappedStream::toList).toList();
|
||||
@@ -661,7 +661,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
public void testSplitList() {
|
||||
final List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);
|
||||
List<List<Integer>> lists = wrap(list).splitList(2).toList();
|
||||
Assert.assertEquals(ListUtil.split(list, 2), lists);
|
||||
Assert.assertEquals(ListUtil.partition(list, 2), lists);
|
||||
|
||||
// 指定长度 大于等于 列表长度
|
||||
lists = wrap(list).splitList(list.size()).toList();
|
||||
|
Reference in New Issue
Block a user