add Base62 Inverted

This commit is contained in:
Looly
2022-03-20 21:20:51 +08:00
parent 3e7dd16c43
commit 9b16947508
4 changed files with 272 additions and 80 deletions

View File

@@ -1,5 +1,6 @@
package cn.hutool.core.codec;
import cn.hutool.core.util.RandomUtil;
import org.junit.Assert;
import org.junit.Test;
@@ -20,4 +21,30 @@ public class Base62Test {
String decodeStr = Base62.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeInvertedTest() {
String a = "伦家是一个非常长的字符串66";
String encode = Base62.encodeInverted(a);
Assert.assertEquals("17Vku8w4jmg8Dqf8LK9vnNKDmoEwN4RjmVA6f0xSlRRt53IkbNQO", encode);
String decodeStr = Base62.decodeStrInverted(encode);
Assert.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeRandomTest() {
String a = RandomUtil.randomString(RandomUtil.randomInt(1000));
String encode = Base62.encode(a);
String decodeStr = Base62.decodeStr(encode);
Assert.assertEquals(a, decodeStr);
}
@Test
public void encodeAndDecodeInvertedRandomTest() {
String a = RandomUtil.randomString(RandomUtil.randomInt(1000));
String encode = Base62.encodeInverted(a);
String decodeStr = Base62.decodeStrInverted(encode);
Assert.assertEquals(a, decodeStr);
}
}