mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
add method
This commit is contained in:
@@ -101,4 +101,15 @@ public class ListUtilTest {
|
||||
int[] d1 = ListUtil.page(0,8,a).stream().mapToInt(Integer::valueOf).toArray();
|
||||
Assert.assertArrayEquals(new int[]{1,2,3,4,5},d1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void subTest(){
|
||||
final List<Integer> of = ListUtil.of(1, 2, 3, 4);
|
||||
final List<Integer> sub = ListUtil.sub(of, 2, 4);
|
||||
sub.remove(0);
|
||||
|
||||
// 对子列表操作不影响原列表
|
||||
Assert.assertEquals(4, of.size());
|
||||
Assert.assertEquals(1, sub.size());
|
||||
}
|
||||
}
|
||||
|
@@ -17,7 +17,7 @@ import java.util.concurrent.CountDownLatch;
|
||||
|
||||
/**
|
||||
* {@link IdUtil} 单元测试
|
||||
*
|
||||
*
|
||||
* @author looly
|
||||
*
|
||||
*/
|
||||
@@ -31,12 +31,12 @@ public class IdUtilTest {
|
||||
String randomUUID = IdUtil.randomUUID();
|
||||
Assert.assertEquals(36, randomUUID.length());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void fastUUIDTest() {
|
||||
String simpleUUID = IdUtil.fastSimpleUUID();
|
||||
Assert.assertEquals(32, simpleUUID.length());
|
||||
|
||||
|
||||
String randomUUID = IdUtil.fastUUID();
|
||||
Assert.assertEquals(36, randomUUID.length());
|
||||
}
|
||||
@@ -60,25 +60,26 @@ public class IdUtilTest {
|
||||
}
|
||||
Console.log(timer.interval());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void objectIdTest() {
|
||||
String id = IdUtil.objectId();
|
||||
Assert.assertEquals(24, id.length());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void createSnowflakeTest() {
|
||||
Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
||||
long id = snowflake.nextId();
|
||||
Assert.assertTrue(id > 0);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void snowflakeBenchTest() {
|
||||
final Set<Long> set = new ConcurrentHashSet<>();
|
||||
final Snowflake snowflake = IdUtil.createSnowflake(1, 1);
|
||||
|
||||
|
||||
//线程数
|
||||
int threadCount = 100;
|
||||
//每个线程生成的ID数
|
||||
@@ -94,7 +95,7 @@ public class IdUtilTest {
|
||||
latch.countDown();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//等待全部线程结束
|
||||
try {
|
||||
latch.await();
|
||||
@@ -103,11 +104,12 @@ public class IdUtilTest {
|
||||
}
|
||||
Assert.assertEquals(threadCount * idCountPerThread, set.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void snowflakeBenchTest2() {
|
||||
final Set<Long> set = new ConcurrentHashSet<>();
|
||||
|
||||
|
||||
//线程数
|
||||
int threadCount = 100;
|
||||
//每个线程生成的ID数
|
||||
@@ -123,7 +125,7 @@ public class IdUtilTest {
|
||||
latch.countDown();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
//等待全部线程结束
|
||||
try {
|
||||
latch.await();
|
||||
|
Reference in New Issue
Block a user