mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-07-21 15:09:48 +08:00
fix code
This commit is contained in:
@@ -0,0 +1,119 @@
|
||||
package cn.hutool.core.codec.hash.metro;
|
||||
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
public class MetroHash128Test {
|
||||
@Test
|
||||
public void testEmpty() {
|
||||
Assert.assertEquals("5F3CA3D41D1CB4606B14684C65FB6", h128(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1Low() {
|
||||
Assert.assertEquals("E84D9EA70174C3184AC6E55552310F85", h128("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1High() {
|
||||
Assert.assertEquals("9A5BCED4C3CA98CADE13388E3C14C215", h128("é"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2Palindrome() {
|
||||
Assert.assertEquals("3DDDF558587273E1FD034EC7CC917AC8", h128("aa"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
Assert.assertEquals("458E6A18B65C38AD2552335402A068A2", h128("ab"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3PalindromeLow() {
|
||||
Assert.assertEquals("19725A6E67A8DD1A84E3C844A20DA938", h128("aaa"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3PalindromeHigh() {
|
||||
Assert.assertEquals("1DD9CC1D29B5080D5F9F171FB2C50CBB", h128("ééé"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
Assert.assertEquals("89AB9CDB9FAF7BA71CD86385C1F801A5", h128("abc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4Palindrome() {
|
||||
Assert.assertEquals("AFD0BBB3764CA0539E46B914B8CB8911", h128("poop"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4() {
|
||||
Assert.assertEquals("D11B6DB94FE20E3884F3829AD6613D19", h128("fart"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5() {
|
||||
Assert.assertEquals("D45A3A74885F9C842081929D2E9A3A3B", h128("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test12() {
|
||||
Assert.assertEquals("A7CEC59B03A9053BA6009EEEC81E81F5", h128("Hello World!"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test31() {
|
||||
Assert.assertEquals("980CA7496A1B26D24E529DFB2B3A870",
|
||||
h128("The Quick Brown Fox Jumped Over"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test32() {
|
||||
Assert.assertEquals("76663CEA442E22F86A6CB41FBA896B9B",
|
||||
h128("The Quick Brown Fox Jumped Over "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLonger() {
|
||||
Assert.assertEquals("7010B2D7C8A3515AE3CA4DBBD9ED30D0",
|
||||
h128("The Quick Brown Fox Jumped Over The Lazy Dog"));
|
||||
}
|
||||
|
||||
static final byte[] ENDIAN =
|
||||
StrUtil.utf8Bytes("012345678901234567890123456789012345678901234567890123456789012");
|
||||
|
||||
@Test
|
||||
public void testLittleEndian() {
|
||||
final ByteBuffer output = ByteBuffer.allocate(16);
|
||||
MetroHash128.of(0).apply(ByteBuffer.wrap(ENDIAN)).write(output, ByteOrder.LITTLE_ENDIAN);
|
||||
Assert.assertEquals("C77CE2BFA4ED9F9B0548B2AC5074A297", hex(output.array()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigEndian() {
|
||||
final ByteBuffer output = ByteBuffer.allocate(16);
|
||||
MetroHash128.of(0).apply(ByteBuffer.wrap(ENDIAN)).write(output, ByteOrder.BIG_ENDIAN);
|
||||
Assert.assertEquals("97A27450ACB248059B9FEDA4BFE27CC7", hex(output.array()));
|
||||
}
|
||||
|
||||
static String h128(final String input) {
|
||||
final MetroHash128 mh = MetroHash128.of(0).apply(ByteBuffer.wrap(StrUtil.utf8Bytes(input)));
|
||||
return hex(mh.getHigh()) + hex(mh.getLow());
|
||||
}
|
||||
|
||||
private static String hex(final long value){
|
||||
return HexUtil.toHex(value).toUpperCase();
|
||||
}
|
||||
|
||||
private static String hex(final byte[] bytes){
|
||||
return HexUtil.encodeHexStr(bytes).toUpperCase();
|
||||
}
|
||||
}
|
@@ -0,0 +1,118 @@
|
||||
package cn.hutool.core.codec.hash.metro;
|
||||
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.nio.ByteOrder;
|
||||
|
||||
/**
|
||||
* 来自:https://github.com/postamar/java-metrohash/blob/master/src/test/java/util/hash/MetroHashTest64.java
|
||||
*/
|
||||
public class MetroHash64Test {
|
||||
@Test
|
||||
public void testEmpty() {
|
||||
Assert.assertEquals("705FB008071E967D", h64(""));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1Low() {
|
||||
Assert.assertEquals("AF6F242B7ED32BCB", h64("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1High() {
|
||||
Assert.assertEquals("D51BA21D219C37B3", h64("é"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2Palindrome() {
|
||||
Assert.assertEquals("3CF3A8F204CAE1B6", h64("aa"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test2() {
|
||||
Assert.assertEquals("CD2EA2738FC27D98", h64("ab"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3PalindromeLow() {
|
||||
Assert.assertEquals("E59031D8D046D241", h64("aaa"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3PalindromeHigh() {
|
||||
Assert.assertEquals("FE8325DC6F40511D", h64("ééé"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test3() {
|
||||
Assert.assertEquals("ED4F5524E6FAFFBB", h64("abc"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4Palindrome() {
|
||||
Assert.assertEquals("CD77F739885CCB2C", h64("poop"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test4() {
|
||||
Assert.assertEquals("B642DCB026D9573C", h64("fart"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test5() {
|
||||
Assert.assertEquals("A611009FEE6AF8B", h64("Hello"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test12() {
|
||||
Assert.assertEquals("14BCB49B74E3B404", h64("Hello World!"));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void test31() {
|
||||
Assert.assertEquals("D27A7BFACC320E2F",
|
||||
h64("The Quick Brown Fox Jumped Over"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test32() {
|
||||
Assert.assertEquals("C313A3A811EAB43B",
|
||||
h64("The Quick Brown Fox Jumped Over "));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLonger() {
|
||||
Assert.assertEquals("C7047C2FCA234C05",
|
||||
h64("The Quick Brown Fox Jumped Over The Lazy Dog"));
|
||||
}
|
||||
|
||||
static final byte[] ENDIAN =
|
||||
StrUtil.utf8Bytes("012345678901234567890123456789012345678901234567890123456789012");
|
||||
|
||||
@Test
|
||||
public void testLittleEndian() {
|
||||
final ByteBuffer output = ByteBuffer.allocate(8);
|
||||
MetroHash64.of(0).apply(ByteBuffer.wrap(ENDIAN)).write(output, ByteOrder.LITTLE_ENDIAN);
|
||||
Assert.assertEquals("6B753DAE06704BAD", hex(output.array()));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBigEndian() {
|
||||
final ByteBuffer output = ByteBuffer.allocate(8);
|
||||
MetroHash64.of(0).apply(ByteBuffer.wrap(ENDIAN)).write(output, ByteOrder.BIG_ENDIAN);
|
||||
Assert.assertEquals("AD4B7006AE3D756B", hex(output.array()));
|
||||
}
|
||||
|
||||
private String h64(final String value) {
|
||||
return HexUtil.toHex(MetroHash64.of(0).hash64(StrUtil.utf8Bytes(value))).toUpperCase();
|
||||
}
|
||||
|
||||
private static String hex(final byte[] bytes){
|
||||
return HexUtil.encodeHexStr(bytes).toUpperCase();
|
||||
}
|
||||
}
|
@@ -1,10 +1,11 @@
|
||||
package cn.hutool.core.codec.hash;
|
||||
package cn.hutool.core.codec.hash.metro;
|
||||
|
||||
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.codec.HexUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import cn.hutool.core.codec.hash.CityHash;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import cn.hutool.core.util.CharsetUtil;
|
||||
import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
@@ -16,22 +17,32 @@ public class MetroHashTest {
|
||||
|
||||
@Test
|
||||
public void testEmpty() {
|
||||
Assert.assertEquals("31290877cceaea29", HexUtil.toHex(MetroHash.INSTANCE.hash64(StrUtil.utf8Bytes(""), 0)));
|
||||
Assert.assertEquals("705fb008071e967d", HexUtil.toHex(MetroHash64.of(0).hash64(StrUtil.utf8Bytes(""))));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1Low() {
|
||||
Assert.assertEquals("AF6F242B7ED32BCB", h64("a"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test1High() {
|
||||
Assert.assertEquals("D51BA21D219C37B3", h64("é"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metroHash64Test() {
|
||||
final byte[] str = "我是一段测试123".getBytes(CharsetUtil.UTF_8);
|
||||
final long hash64 = MetroHash.INSTANCE.hash64(str);
|
||||
Assert.assertEquals(62920234463891865L, hash64);
|
||||
final long hash64 = MetroHash64.of(0).hash64(str);
|
||||
Assert.assertEquals(147395857347476456L, hash64);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void metroHash128Test() {
|
||||
final byte[] str = "我是一段测试123".getBytes(CharsetUtil.UTF_8);
|
||||
final long[] hash128 = MetroHash.INSTANCE.hash128(str).getLongArray();
|
||||
Assert.assertEquals(4956592424592439349L, hash128[0]);
|
||||
Assert.assertEquals(6301214698325086246L, hash128[1]);
|
||||
final long[] hash128 = MetroHash128.of(0).hash128(str).getLongArray();
|
||||
Assert.assertEquals(228255164667538345L, hash128[0]);
|
||||
Assert.assertEquals(-6394585948993412256L, hash128[1]);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -49,7 +60,7 @@ public class MetroHashTest {
|
||||
|
||||
final long startMetro = System.currentTimeMillis();
|
||||
for (final String s : strArray) {
|
||||
MetroHash.INSTANCE.hash64(StrUtil.utf8Bytes(s));
|
||||
MetroHash64.of(0).hash64(StrUtil.utf8Bytes(s));
|
||||
}
|
||||
final long endMetro = System.currentTimeMillis();
|
||||
|
||||
@@ -73,7 +84,7 @@ public class MetroHashTest {
|
||||
|
||||
final long startMetro = System.currentTimeMillis();
|
||||
for (final String s : strArray) {
|
||||
MetroHash.INSTANCE.hash128(StrUtil.utf8Bytes(s));
|
||||
MetroHash128.of(0).hash128(StrUtil.utf8Bytes(s));
|
||||
}
|
||||
final long endMetro = System.currentTimeMillis();
|
||||
|
||||
@@ -90,4 +101,8 @@ public class MetroHashTest {
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private String h64(final String value) {
|
||||
return HexUtil.toHex(MetroHash64.of(0).hash64(StrUtil.utf8Bytes(value))).toUpperCase();
|
||||
}
|
||||
}
|
@@ -7,13 +7,7 @@ import lombok.Data;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* {@link IterUtil} 单元测试
|
||||
|
@@ -4,7 +4,6 @@ import cn.hutool.core.collection.ListUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
@@ -11,17 +11,7 @@ import cn.hutool.core.util.RandomUtil;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.BufferedInputStream;
|
||||
import java.io.BufferedOutputStream;
|
||||
import java.io.BufferedReader;
|
||||
import java.io.BufferedWriter;
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.PushbackReader;
|
||||
import java.io.StringReader;
|
||||
import java.io.StringWriter;
|
||||
import java.util.ArrayList;
|
||||
import java.io.*;
|
||||
import java.util.List;
|
||||
|
||||
public class IoUtilTest {
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package cn.hutool.core.builder;
|
||||
package cn.hutool.core.lang.builder;
|
||||
|
||||
import cn.hutool.core.lang.builder.GenericBuilder;
|
||||
import cn.hutool.core.text.StrUtil;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
@@ -39,13 +39,13 @@ public class BoundTest {
|
||||
// getValue
|
||||
Assert.assertNull(bound.getValue());
|
||||
// toString
|
||||
Assert.assertEquals("(" + "-\u221e", bound.descBound());
|
||||
Assert.assertEquals("(" + "-∞", bound.descBound());
|
||||
// compareTo
|
||||
Assert.assertEquals(0, bound.compareTo(bound));
|
||||
Assert.assertEquals(-1, bound.compareTo(Bound.atMost(1)));
|
||||
|
||||
Assert.assertEquals(BoundedRange.all(), bound.toRange());
|
||||
Assert.assertEquals("{x | x > -\u221e}", bound.toString());
|
||||
Assert.assertEquals("{x | x > -∞}", bound.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -60,13 +60,13 @@ public class BoundTest {
|
||||
// getValue
|
||||
Assert.assertNull(bound.getValue());
|
||||
// toString
|
||||
Assert.assertEquals("+\u221e" + ")", bound.descBound());
|
||||
Assert.assertEquals("+∞" + ")", bound.descBound());
|
||||
// compareTo
|
||||
Assert.assertEquals(0, bound.compareTo(bound));
|
||||
Assert.assertEquals(1, bound.compareTo(Bound.atMost(1)));
|
||||
|
||||
Assert.assertEquals(BoundedRange.all(), bound.toRange());
|
||||
Assert.assertEquals("{x | x < +\u221e}", bound.toString());
|
||||
Assert.assertEquals("{x | x < +∞}", bound.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -1,6 +1,5 @@
|
||||
package cn.hutool.core.reflect;
|
||||
|
||||
import cn.hutool.core.reflect.ActualTypeMapperPool;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -9,7 +8,7 @@ import java.util.Map;
|
||||
|
||||
/**
|
||||
* 见:<a href="https://gitee.com/dromara/hutool/pulls/447/files">https://gitee.com/dromara/hutool/pulls/447/files</a>
|
||||
*
|
||||
* <p>
|
||||
* TODO 同时继承泛型和实现泛型接口需要解析,此处为F
|
||||
*/
|
||||
public class ActualTypeMapperPoolTest {
|
||||
|
@@ -591,9 +591,7 @@ public class AbstractEnhancedWrappedStreamTest {
|
||||
public void testMapMulti() {
|
||||
Assert.assertEquals(
|
||||
asList(1, 2, 3),
|
||||
wrap(1, 2, 3).mapMulti((t, builder) -> {
|
||||
builder.accept(t);
|
||||
}).toList()
|
||||
wrap(1, 2, 3).mapMulti((t, builder) -> builder.accept(t)).toList()
|
||||
);
|
||||
}
|
||||
|
||||
|
@@ -59,6 +59,7 @@ public class CharSequenceUtilTest {
|
||||
Assert.assertEquals("/", result);
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnnecessaryUnicodeEscape")
|
||||
@Test
|
||||
public void normalizeTest() {
|
||||
// https://blog.csdn.net/oscar999/article/details/105326270
|
||||
@@ -155,6 +156,7 @@ public class CharSequenceUtilTest {
|
||||
Assert.assertNull(CharSequenceUtil.removeSuffixIgnoreCase(null, "ABCdef"));
|
||||
}
|
||||
|
||||
@SuppressWarnings("ConstantValue")
|
||||
@Test
|
||||
public void trimToNullTest(){
|
||||
String a = " ";
|
||||
|
@@ -8,7 +8,7 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
public class issueI5Q4HDTest {
|
||||
public class IssueI5Q4HDTest {
|
||||
|
||||
@Test
|
||||
public void matchAllTest(){
|
@@ -27,6 +27,7 @@ public class CharUtilTest {
|
||||
Assert.assertTrue(CharUtil.isChar(a));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnnecessaryUnicodeEscape")
|
||||
@Test
|
||||
public void isBlankCharTest(){
|
||||
final char a = '\u00A0';
|
||||
@@ -56,6 +57,7 @@ public class CharUtilTest {
|
||||
Assert.assertEquals('⑳', CharUtil.toCloseByNumber(20));
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnnecessaryUnicodeEscape")
|
||||
@Test
|
||||
public void issueI5UGSQTest(){
|
||||
char c = '\u3164';
|
||||
|
Reference in New Issue
Block a user