Skip to content

Commit 450763b

Browse files
committed
add some test case
1 parent ddccce4 commit 450763b

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.tron.plugins.utils;
2+
3+
import lombok.extern.slf4j.Slf4j;
4+
import org.junit.Assert;
5+
import org.junit.Test;
6+
7+
@Slf4j
8+
public class ByteArrayTest {
9+
10+
@Test
11+
public void testToStrToInt() {
12+
String test = "abc";
13+
byte[] testBytes = test.getBytes();
14+
Assert.assertEquals(test, ByteArray.toStr(testBytes));
15+
16+
int i = 5;
17+
Assert.assertEquals(ByteArray.toInt(ByteArray.fromInt(i)), 5);
18+
}
19+
20+
@Test
21+
public void testFromHexString() {
22+
Assert.assertArrayEquals(ByteArray.EMPTY_BYTE_ARRAY, ByteArray.fromHexString(null));
23+
24+
Assert.assertArrayEquals(ByteArray.fromHexString("12"), ByteArray.fromHexString("0x12"));
25+
26+
Assert.assertArrayEquals(ByteArray.fromHexString("0x2"), ByteArray.fromHexString("0x02"));
27+
}
28+
29+
@Test
30+
public void testCompareUnsigned() {
31+
byte[] a = new byte[] {1, 2};
32+
Assert.assertEquals(0, ByteArray.compareUnsigned(a, a));
33+
Assert.assertEquals(-1, ByteArray.compareUnsigned(null, a));
34+
Assert.assertEquals(1, ByteArray.compareUnsigned(a, null));
35+
36+
byte[] b = new byte[] {1, 3};
37+
Assert.assertEquals(-1, ByteArray.compareUnsigned(a, b));
38+
Assert.assertEquals(1, ByteArray.compareUnsigned(b, a));
39+
40+
byte[] c = new byte[] {1, 2, 3};
41+
Assert.assertEquals(-1, ByteArray.compareUnsigned(a, c));
42+
Assert.assertEquals(1, ByteArray.compareUnsigned(c, a));
43+
}
44+
}

0 commit comments

Comments
 (0)