mirror of
https://gitee.com/dromara/hutool.git
synced 2025-05-04 12:47:59 +08:00
fix test
This commit is contained in:
parent
7174b49906
commit
692397f313
@ -20,6 +20,7 @@
|
||||
|
||||
### Bug修复
|
||||
* 【core】 修复NetUtil.getUsableLocalPort问题(pr#69@Gitee)
|
||||
* 【core】 修复MathUtil.arrangementSelect重复元素导致无结果问题(issue#529@Gitee)
|
||||
|
||||
-------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
@ -5,6 +5,7 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import cn.hutool.core.util.ArrayUtil;
|
||||
import cn.hutool.core.util.NumberUtil;
|
||||
|
||||
/**
|
||||
@ -68,6 +69,7 @@ public class Arrangement implements Serializable{
|
||||
|
||||
/**
|
||||
* 全排列选择(列表全部参与排列)
|
||||
*
|
||||
* @return 所有排列列表
|
||||
*/
|
||||
public List<String[]> select() {
|
||||
@ -82,7 +84,7 @@ public class Arrangement implements Serializable{
|
||||
*/
|
||||
public List<String[]> select(int m) {
|
||||
final List<String[]> result = new ArrayList<>((int) count(this.datas.length, m));
|
||||
select(new String[m], 0, result);
|
||||
select(this.datas, new String[m], 0, result);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -100,34 +102,27 @@ public class Arrangement implements Serializable{
|
||||
}
|
||||
|
||||
/**
|
||||
* 排列选择
|
||||
* 排列选择<br>
|
||||
* 排列方式为先从数据数组中取出一个元素,再把剩余的元素作为新的基数,依次列推,直到选择到足够的元素
|
||||
*
|
||||
* @param datas 选择的基数
|
||||
* @param dataList 待选列表
|
||||
* @param resultList 前面(resultIndex-1)个的排列结果
|
||||
* @param resultIndex 选择索引,从0开始
|
||||
* @param result 最终结果
|
||||
*/
|
||||
private void select(String[] resultList, int resultIndex, List<String[]> result) {
|
||||
int resultLen = resultList.length;
|
||||
if (resultIndex >= resultLen) { // 全部选择完时,输出排列结果
|
||||
private void select(String[] datas, String[] resultList, int resultIndex, List<String[]> result) {
|
||||
if (resultIndex >= resultList.length) { // 全部选择完时,输出排列结果
|
||||
if (false == result.contains(resultList)) {
|
||||
result.add(Arrays.copyOf(resultList, resultList.length));
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// 递归选择下一个
|
||||
for (int i = 0; i < datas.length; i++) {
|
||||
// 判断待选项是否存在于排列结果中
|
||||
boolean exists = false;
|
||||
for (int j = 0; j < resultIndex; j++) {
|
||||
if (datas[i].equals(resultList[j])) {
|
||||
exists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (false == exists) { // 排列结果不存在该项,才可选择
|
||||
resultList[resultIndex] = datas[i];
|
||||
select(resultList, resultIndex + 1, result);
|
||||
}
|
||||
select(ArrayUtil.remove(datas, i), resultList, resultIndex + 1, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,8 +3,11 @@ package cn.hutool.core.math;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
import cn.hutool.core.lang.Console;
|
||||
|
||||
/**
|
||||
* 排列单元测试
|
||||
* @author looly
|
||||
@ -51,4 +54,13 @@ public class ArrangementTest {
|
||||
List<String[]> list2 = arrangement.select(0);
|
||||
Assert.assertTrue(1 == list2.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Ignore
|
||||
public void selectTest2() {
|
||||
List<String[]> list = MathUtil.arrangementSelect(new String[] { "1", "1", "3", "4" });
|
||||
for (String[] strings : list) {
|
||||
Console.log(strings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -484,6 +484,17 @@ public class ExcelWriter extends ExcelBase<ExcelWriter> {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置默认行高,值为一个点的高度
|
||||
*
|
||||
* @param height 高度
|
||||
* @return this
|
||||
* @since 4.6.5
|
||||
*/
|
||||
public ExcelWriter setDefaultRowHeight(int height) {
|
||||
return setRowHeight(-1, height);
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置行高,值为一个点的高度
|
||||
*
|
||||
|
@ -75,7 +75,7 @@ public class ExcelWriteTest {
|
||||
rows.add(ObjectUtil.clone(row1));
|
||||
}
|
||||
|
||||
String filePath = "e:/writeTest.xlsx";
|
||||
String filePath = "f:/test/writeTest.xlsx";
|
||||
FileUtil.del(filePath);
|
||||
// 通过工具类创建writer
|
||||
ExcelWriter writer = ExcelUtil.getWriter(filePath);
|
||||
|
Loading…
Reference in New Issue
Block a user