del methdos

This commit is contained in:
Looly
2022-06-07 13:58:24 +08:00
parent 2dbfb5a8cc
commit 084870261f
17 changed files with 425 additions and 649 deletions

View File

@@ -3,7 +3,7 @@ package cn.hutool.core.collection;
import cn.hutool.core.collection.iter.LineIter;
import cn.hutool.core.collection.iter.PartitionIter;
import cn.hutool.core.io.resource.ResourceUtil;
import cn.hutool.core.math.NumberUtil;
import cn.hutool.core.util.ArrayUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -26,7 +26,7 @@ public class PartitionIterTest {
final PartitionIter<Integer> iter = new PartitionIter<>(list.iterator(), 3);
int max = 0;
for (final List<Integer> lines : iter) {
max = NumberUtil.max(max, NumberUtil.max(lines.toArray(new Integer[0])));
max = ArrayUtil.max(max, ArrayUtil.max(lines.toArray(new Integer[0])));
}
Assert.assertEquals(45, max);
}

View File

@@ -0,0 +1,44 @@
package cn.hutool.core.math;
import org.junit.Assert;
import org.junit.Test;
import java.math.BigInteger;
public class MathUtilTest {
@Test
public void factorialTest(){
long factorial = MathUtil.factorial(0);
Assert.assertEquals(1, factorial);
Assert.assertEquals(1L, MathUtil.factorial(1));
Assert.assertEquals(1307674368000L, MathUtil.factorial(15));
Assert.assertEquals(2432902008176640000L, MathUtil.factorial(20));
factorial = MathUtil.factorial(5, 0);
Assert.assertEquals(120, factorial);
factorial = MathUtil.factorial(5, 1);
Assert.assertEquals(120, factorial);
Assert.assertEquals(5, MathUtil.factorial(5, 4));
Assert.assertEquals(2432902008176640000L, MathUtil.factorial(20, 0));
}
@Test
public void factorialTest2(){
long factorial = MathUtil.factorial(new BigInteger("0")).longValue();
Assert.assertEquals(1, factorial);
Assert.assertEquals(1L, MathUtil.factorial(new BigInteger("1")).longValue());
Assert.assertEquals(1307674368000L, MathUtil.factorial(new BigInteger("15")).longValue());
Assert.assertEquals(2432902008176640000L, MathUtil.factorial(20));
factorial = MathUtil.factorial(new BigInteger("5"), new BigInteger("0")).longValue();
Assert.assertEquals(120, factorial);
factorial = MathUtil.factorial(new BigInteger("5"), BigInteger.ONE).longValue();
Assert.assertEquals(120, factorial);
Assert.assertEquals(5, MathUtil.factorial(new BigInteger("5"), new BigInteger("4")).longValue());
Assert.assertEquals(2432902008176640000L, MathUtil.factorial(new BigInteger("20"), BigInteger.ZERO).longValue());
}
}

View File

@@ -167,27 +167,6 @@ public class ArrayUtilTest {
Assert.assertEquals(values[2], cast[2]);
}
@Test
public void rangeTest() {
final int[] range = ArrayUtil.range(0, 10);
Assert.assertEquals(0, range[0]);
Assert.assertEquals(1, range[1]);
Assert.assertEquals(2, range[2]);
Assert.assertEquals(3, range[3]);
Assert.assertEquals(4, range[4]);
Assert.assertEquals(5, range[5]);
Assert.assertEquals(6, range[6]);
Assert.assertEquals(7, range[7]);
Assert.assertEquals(8, range[8]);
Assert.assertEquals(9, range[9]);
}
@Test(expected = NegativeArraySizeException.class)
public void rangeMinTest() {
//noinspection ResultOfMethodCallIgnored
ArrayUtil.range(0, Integer.MIN_VALUE);
}
@Test
public void maxTest() {
final int max = ArrayUtil.max(1, 2, 13, 4, 5);

View File

@@ -6,7 +6,6 @@ import org.junit.Assert;
import org.junit.Test;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.math.RoundingMode;
/**
@@ -262,18 +261,6 @@ public class NumberUtilTest {
Assert.assertEquals("1234.56", bigDecimal.toString());
}
@Test
public void maxTest() {
final int max = NumberUtil.max(5,4,3,6,1);
Assert.assertEquals(6, max);
}
@Test
public void minTest() {
final int min = NumberUtil.min(5,4,3,6,1);
Assert.assertEquals(1, min);
}
@Test
public void parseIntTest() {
int number = NumberUtil.parseInt("0xFF");
@@ -362,42 +349,6 @@ public class NumberUtilTest {
Assert.assertEquals(0, number);
}
@Test
public void factorialTest(){
long factorial = NumberUtil.factorial(0);
Assert.assertEquals(1, factorial);
Assert.assertEquals(1L, NumberUtil.factorial(1));
Assert.assertEquals(1307674368000L, NumberUtil.factorial(15));
Assert.assertEquals(2432902008176640000L, NumberUtil.factorial(20));
factorial = NumberUtil.factorial(5, 0);
Assert.assertEquals(120, factorial);
factorial = NumberUtil.factorial(5, 1);
Assert.assertEquals(120, factorial);
Assert.assertEquals(5, NumberUtil.factorial(5, 4));
Assert.assertEquals(2432902008176640000L, NumberUtil.factorial(20, 0));
}
@Test
public void factorialTest2(){
long factorial = NumberUtil.factorial(new BigInteger("0")).longValue();
Assert.assertEquals(1, factorial);
Assert.assertEquals(1L, NumberUtil.factorial(new BigInteger("1")).longValue());
Assert.assertEquals(1307674368000L, NumberUtil.factorial(new BigInteger("15")).longValue());
Assert.assertEquals(2432902008176640000L, NumberUtil.factorial(20));
factorial = NumberUtil.factorial(new BigInteger("5"), new BigInteger("0")).longValue();
Assert.assertEquals(120, factorial);
factorial = NumberUtil.factorial(new BigInteger("5"), BigInteger.ONE).longValue();
Assert.assertEquals(120, factorial);
Assert.assertEquals(5, NumberUtil.factorial(new BigInteger("5"), new BigInteger("4")).longValue());
Assert.assertEquals(2432902008176640000L, NumberUtil.factorial(new BigInteger("20"), BigInteger.ZERO).longValue());
}
@Test
public void isPowerOfTwoTest() {
Assert.assertFalse(NumberUtil.isPowerOfTwo(-1));
@@ -462,4 +413,25 @@ public class NumberUtilTest {
Assert.assertFalse(NumberUtil.isDouble(" "));
}
@Test
public void rangeTest() {
final int[] range = NumberUtil.range(0, 10);
Assert.assertEquals(0, range[0]);
Assert.assertEquals(1, range[1]);
Assert.assertEquals(2, range[2]);
Assert.assertEquals(3, range[3]);
Assert.assertEquals(4, range[4]);
Assert.assertEquals(5, range[5]);
Assert.assertEquals(6, range[6]);
Assert.assertEquals(7, range[7]);
Assert.assertEquals(8, range[8]);
Assert.assertEquals(9, range[9]);
Assert.assertEquals(10, range[10]);
}
@Test(expected = NegativeArraySizeException.class)
public void rangeMinTest() {
//noinspection ResultOfMethodCallIgnored
NumberUtil.range(0, Integer.MIN_VALUE);
}
}