|
8 | 8 | public class BcdConversionTest {
|
9 | 9 |
|
10 | 10 | @Test
|
11 |
| - public void testBcdToBinary() { |
12 |
| - int binary = BcdConversion.bcdToBinary(0x1234); |
13 |
| - assertEquals(1234, binary); // BCD 0x1234 should convert to binary 1234 |
| 11 | + public void testBcdToDecimal() { |
| 12 | + int decimal = BcdConversion.bcdToDecimal(0x1234); |
| 13 | + assertEquals(1234, decimal); // BCD 0x1234 should convert to decimal 1234 |
14 | 14 | }
|
15 | 15 |
|
16 | 16 | @Test
|
17 |
| - public void testBinaryToBcd() { |
18 |
| - int bcd = BcdConversion.binaryToBcd(1234); |
19 |
| - assertEquals(0x1234, bcd); // Binary 1234 should convert to BCD 0x1234 |
| 17 | + public void testDecimalToBcd() { |
| 18 | + int bcd = BcdConversion.decimalToBcd(1234); |
| 19 | + assertEquals(0x1234, bcd); // Decimal 1234 should convert to BCD 0x1234 |
20 | 20 | }
|
21 | 21 |
|
22 | 22 | @Test
|
23 |
| - public void testBcdToBinaryZero() { |
24 |
| - int binary = BcdConversion.bcdToBinary(0x0); |
25 |
| - assertEquals(0, binary); // BCD 0x0 should convert to binary 0 |
| 23 | + public void testBcdToDecimalZero() { |
| 24 | + int decimal = BcdConversion.bcdToDecimal(0x0); |
| 25 | + assertEquals(0, decimal); // BCD 0x0 should convert to decimal 0 |
26 | 26 | }
|
27 | 27 |
|
28 | 28 | @Test
|
29 |
| - public void testBinaryToBcdZero() { |
30 |
| - int bcd = BcdConversion.binaryToBcd(0); |
31 |
| - assertEquals(0x0, bcd); // Binary 0 should convert to BCD 0x0 |
| 29 | + public void testDecimalToBcdZero() { |
| 30 | + int bcd = BcdConversion.decimalToBcd(0); |
| 31 | + assertEquals(0x0, bcd); // Decimal 0 should convert to BCD 0x0 |
32 | 32 | }
|
33 | 33 |
|
34 | 34 | @Test
|
35 |
| - public void testBcdToBinarySingleDigit() { |
36 |
| - int binary = BcdConversion.bcdToBinary(0x7); |
37 |
| - assertEquals(7, binary); // BCD 0x7 should convert to binary 7 |
| 35 | + public void testBcdToDecimalSingleDigit() { |
| 36 | + int decimal = BcdConversion.bcdToDecimal(0x7); |
| 37 | + assertEquals(7, decimal); // BCD 0x7 should convert to decimal 7 |
38 | 38 | }
|
39 | 39 |
|
40 | 40 | @Test
|
41 |
| - public void testBinaryToBcdSingleDigit() { |
42 |
| - int bcd = BcdConversion.binaryToBcd(7); |
43 |
| - assertEquals(0x7, bcd); // Binary 7 should convert to BCD 0x7 |
| 41 | + public void testDecimalToBcdSingleDigit() { |
| 42 | + int bcd = BcdConversion.decimalToBcd(7); |
| 43 | + assertEquals(0x7, bcd); // Decimal 7 should convert to BCD 0x7 |
44 | 44 | }
|
45 | 45 |
|
46 | 46 | @Test
|
47 |
| - public void testBcdToBinaryMaxValue() { |
48 |
| - int binary = BcdConversion.bcdToBinary(0x9999); |
49 |
| - assertEquals(9999, binary); // BCD 0x9999 should convert to binary 9999 |
| 47 | + public void testBcdToDecimalMaxValue() { |
| 48 | + int decimal = BcdConversion.bcdToDecimal(0x9999); |
| 49 | + assertEquals(9999, decimal); // BCD 0x9999 should convert to decimal 9999 |
50 | 50 | }
|
51 | 51 |
|
52 | 52 | @Test
|
53 |
| - public void testBinaryToBcdMaxValue() { |
54 |
| - int bcd = BcdConversion.binaryToBcd(9999); |
55 |
| - assertEquals(0x9999, bcd); // Binary 9999 should convert to BCD 0x9999 |
| 53 | + public void testDecimalToBcdMaxValue() { |
| 54 | + int bcd = BcdConversion.decimalToBcd(9999); |
| 55 | + assertEquals(0x9999, bcd); // Decimal 9999 should convert to BCD 0x9999 |
56 | 56 | }
|
57 | 57 |
|
58 | 58 | @Test
|
59 |
| - public void testBcdToBinaryInvalidHighDigit() { |
| 59 | + public void testBcdToDecimalInvalidHighDigit() { |
60 | 60 | // Testing invalid BCD input where one of the digits is > 9
|
61 | 61 | assertThrows(IllegalArgumentException.class, () -> {
|
62 |
| - BcdConversion.bcdToBinary(0x123A); // Invalid BCD, 'A' is not a valid digit |
| 62 | + BcdConversion.bcdToDecimal(0x123A); // Invalid BCD, 'A' is not a valid digit |
63 | 63 | });
|
64 | 64 | }
|
65 | 65 |
|
66 | 66 | @Test
|
67 |
| - public void testBinaryToBcdInvalidValue() { |
| 67 | + public void testDecimalToBcdInvalidValue() { |
68 | 68 | // Testing conversion for numbers greater than 9999, which cannot be represented in BCD
|
69 | 69 | assertThrows(IllegalArgumentException.class, () -> {
|
70 |
| - BcdConversion.binaryToBcd(10000); // 10000 is too large for BCD representation |
| 70 | + BcdConversion.decimalToBcd(10000); // 10000 is too large for BCD representation |
71 | 71 | });
|
72 | 72 | }
|
73 | 73 |
|
74 | 74 | @Test
|
75 |
| - public void testBcdToBinaryLeadingZeroes() { |
76 |
| - int binary = BcdConversion.bcdToBinary(0x0234); |
77 |
| - assertEquals(234, binary); // BCD 0x0234 should convert to binary 234, ignoring leading zero |
| 75 | + public void testBcdToDecimalLeadingZeroes() { |
| 76 | + int decimal = BcdConversion.bcdToDecimal(0x0234); |
| 77 | + assertEquals(234, decimal); // BCD 0x0234 should convert to decimal 234, ignoring leading zero |
78 | 78 | }
|
79 | 79 |
|
80 | 80 | @Test
|
81 |
| - public void testBinaryToBcdLeadingZeroes() { |
82 |
| - int bcd = BcdConversion.binaryToBcd(234); |
83 |
| - assertEquals(0x0234, bcd); // Binary 234 should convert to BCD 0x0234 |
| 81 | + public void testDecimalToBcdLeadingZeroes() { |
| 82 | + int bcd = BcdConversion.decimalToBcd(234); |
| 83 | + assertEquals(0x0234, bcd); // Decimal 234 should convert to BCD 0x0234 |
84 | 84 | }
|
85 | 85 | }
|
0 commit comments