|
7 | 7 |
|
8 | 8 | public class EndianConverterTest {
|
9 | 9 |
|
10 |
| - /** |
11 |
| - * Tests conversion from big-endian to little-endian using parameterized inputs. |
12 |
| - */ |
13 | 10 | @ParameterizedTest
|
14 | 11 | @CsvSource({
|
15 |
| - "0x12345678, 0x78563412", "0x00000000, 0x00000000", "0x01000000, 0x00000001", |
16 |
| - "0xFFFFFFFF, 0xFFFFFFFF", // -1 in two’s complement |
17 |
| - "0x7F000000, 0x0000007F" // Positive boundary case |
| 12 | + "0x78563412, 0x12345678", |
| 13 | + "0x00000000, 0x00000000", |
| 14 | + "0x00000001, 0x01000000", |
| 15 | + "0xFFFFFFFF, 0xFFFFFFFF", // -1 in two's complement |
| 16 | + "0x0000007F, 0x7F000000" // Positive boundary case |
18 | 17 | })
|
19 |
| - public void |
20 |
| - testBigToLittleEndian(int input, int expected) { |
21 |
| - assertEquals(expected, EndianConverter.bigToLittleEndian(input)); |
| 18 | + public void testLittleToBigEndian(String inputHex, String expectedHex) { |
| 19 | + int input = (int) Long.parseLong(inputHex.substring(2), 16); // Convert hex string to int |
| 20 | + int expected = (int) Long.parseLong(expectedHex.substring(2), 16); // Convert hex string to int |
| 21 | + assertEquals(expected, EndianConverter.littleToBigEndian(input)); |
22 | 22 | }
|
23 | 23 |
|
24 |
| - /** |
25 |
| - * Tests conversion from little-endian to big-endian using parameterized inputs. |
26 |
| - */ |
27 | 24 | @ParameterizedTest
|
28 | 25 | @CsvSource({
|
29 |
| - "0x78563412, 0x12345678", "0x00000000, 0x00000000", "0x00000001, 0x01000000", |
30 |
| - "0xFFFFFFFF, 0xFFFFFFFF", // -1 in two’s complement |
31 |
| - "0x0000007F, 0x7F000000" // Positive boundary case |
| 26 | + "0x12345678, 0x78563412", |
| 27 | + "0x00000000, 0x00000000", |
| 28 | + "0x01000000, 0x00000001", |
| 29 | + "0xFFFFFFFF, 0xFFFFFFFF", // -1 in two's complement |
| 30 | + "0x7F000000, 0x0000007F" // Positive boundary case |
32 | 31 | })
|
33 |
| - public void |
34 |
| - testLittleToBigEndian(int input, int expected) { |
35 |
| - assertEquals(expected, EndianConverter.littleToBigEndian(input)); |
| 32 | + public void testBigToLittleEndian(String inputHex, String expectedHex) { |
| 33 | + int input = (int) Long.parseLong(inputHex.substring(2), 16); // Convert hex string to int |
| 34 | + int expected = (int) Long.parseLong(expectedHex.substring(2), 16); // Convert hex string to int |
| 35 | + assertEquals(expected, EndianConverter.bigToLittleEndian(input)); |
36 | 36 | }
|
37 | 37 | }
|
0 commit comments