add method

This commit is contained in:
Looly
2021-06-11 13:17:35 +08:00
parent 93b383c2b7
commit e2de04d36f
11 changed files with 617 additions and 554 deletions

View File

@@ -145,4 +145,5 @@ public class ImgUtilTest {
String mainColor = ImgUtil.getMainColor(read, new int[]{64,84,116});
System.out.println(mainColor);
}
}

View File

@@ -5,43 +5,43 @@ import java.util.List;
import org.junit.Assert;
import org.junit.Test;
import cn.hutool.core.text.StrSpliter;
import cn.hutool.core.text.StrSplitter;
/**
* {@link StrSpliter} 单元测试
* {@link StrSplitter} 单元测试
* @author Looly
*
*/
public class StrSpliterTest {
@Test
public void splitByCharTest(){
String str1 = "a, ,efedsfs, ddf";
List<String> split = StrSpliter.split(str1, ',', 0, true, true);
List<String> split = StrSplitter.split(str1, ',', 0, true, true);
Assert.assertEquals("ddf", split.get(2));
Assert.assertEquals(3, split.size());
}
@Test
public void splitByStrTest(){
String str1 = "aabbccaaddaaee";
List<String> split = StrSpliter.split(str1, "aa", 0, true, true);
List<String> split = StrSplitter.split(str1, "aa", 0, true, true);
Assert.assertEquals("ee", split.get(2));
Assert.assertEquals(3, split.size());
}
@Test
public void splitByBlankTest(){
String str1 = "aa bbccaa ddaaee";
List<String> split = StrSpliter.split(str1, 0);
List<String> split = StrSplitter.split(str1, 0);
Assert.assertEquals("ddaaee", split.get(2));
Assert.assertEquals(3, split.size());
}
@Test
public void splitPathTest(){
String str1 = "/use/local/bin";
List<String> split = StrSpliter.splitPath(str1, 0);
List<String> split = StrSplitter.splitPath(str1, 0);
Assert.assertEquals("bin", split.get(2));
Assert.assertEquals(3, split.size());
}

View File

@@ -1,6 +1,7 @@
package cn.hutool.core.util;
import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.Console;
import org.junit.Assert;
import org.junit.Test;
@@ -161,6 +162,23 @@ public class NumberUtilTest {
Assert.assertEquals("299,792,458", format);
}
@Test(expected = IllegalArgumentException.class)
public void decimalFormatNaNTest(){
Double a = 0D;
Double b = 0D;
Double c = a / b;
Console.log(NumberUtil.decimalFormat("#%", c));
}
@Test(expected = IllegalArgumentException.class)
public void decimalFormatNaNTest2(){
Double a = 0D;
Double b = 0D;
Console.log(NumberUtil.decimalFormat("#%", a / b));
}
@Test
public void decimalFormatDoubleTest() {
Double c = 467.8101;