This commit is contained in:
Looly
2022-10-24 11:55:12 +08:00
parent a64155e0cc
commit 34dc797d23
3 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,56 @@
package cn.hutool.core.collection.partition;
import cn.hutool.core.collection.ListUtil;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.List;
public class PartitionTest {
@Test
public void sizeTest() {
final ArrayList<Integer> list = ListUtil.of(1, 2, 3, 4, 5);
final Partition<Integer> partition = new Partition<>(list, 4);
Assert.assertEquals(2, partition.size());
}
@Test
public void getSizeTest() {
List<Integer> mockedList = makingList(19);
Partition<Integer> partition = new Partition<>(mockedList, 10);
Assert.assertEquals(2, partition.size());
mockedList = makingList(11);
partition = new Partition<>(mockedList, 10);
Assert.assertEquals(2, partition.size());
mockedList = makingList(10);
partition = new Partition<>(mockedList, 10);
Assert.assertEquals(1, partition.size());
mockedList = makingList(9);
partition = new Partition<>(mockedList, 10);
Assert.assertEquals(1, partition.size());
mockedList = makingList(5);
partition = new Partition<>(mockedList, 10);
Assert.assertEquals(1, partition.size());
}
@Test
public void getZeroSizeTest() {
final List<Integer> mockedList = makingList(0);
final Partition<Integer> partition = new Partition<>(mockedList, 10);
Assert.assertEquals(0, partition.size());
}
private List<Integer> makingList(final int length) {
final List<Integer> list = ListUtil.of();
for (int i = 0; i < length; i++) {
list.add(i);
}
return list;
}
}