forked from TheAlgorithms/Java
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBcdConversionTest.java
65 lines (56 loc) · 1.72 KB
/
BcdConversionTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.thealgorithms.bitmanipulation;
import static org.junit.jupiter.api.Assertions.assertEquals;
import org.junit.jupiter.api.Test;
/**
* Unit tests for the BcdConversion class.
*/
public class BcdConversionTest {
/**
* Test the bcdToBinary method with a BCD number.
*/
@Test
public void testBcdToBinary() {
int binary = BcdConversion.bcdToBinary(0x1234);
assertEquals(1234, binary); // BCD 0x1234 should convert to binary 1234
}
/**
* Test the binaryToBcd method with a binary number.
*/
@Test
public void testBinaryToBcd() {
int bcd = BcdConversion.binaryToBcd(1234);
assertEquals(0x1234, bcd); // Binary 1234 should convert to BCD 0x1234
}
/**
* Test the bcdToBinary method with zero.
*/
@Test
public void testBcdToBinaryZero() {
int binary = BcdConversion.bcdToBinary(0x0);
assertEquals(0, binary); // BCD 0x0 should convert to binary 0
}
/**
* Test the binaryToBcd method with zero.
*/
@Test
public void testBinaryToBcdZero() {
int bcd = BcdConversion.binaryToBcd(0);
assertEquals(0x0, bcd); // Binary 0 should convert to BCD 0x0
}
/**
* Test the bcdToBinary method with a single digit BCD number.
*/
@Test
public void testBcdToBinarySingleDigit() {
int binary = BcdConversion.bcdToBinary(0x7);
assertEquals(7, binary); // BCD 0x7 should convert to binary 7
}
/**
* Test the binaryToBcd method with a single digit binary number.
*/
@Test
public void testBinaryToBcdSingleDigit() {
int bcd = BcdConversion.binaryToBcd(7);
assertEquals(0x7, bcd); // Binary 7 should convert to BCD 0x7
}
}