@@ -13,25 +13,25 @@ public class TwosComplementTest {
1313 @ Test
1414 public void testTwosComplement_AllZeroes () {
1515 // Test with a binary number consisting entirely of zeroes
16- assertEquals ("0000 " , TwosComplement .twosComplement ("0000" ));
17- assertEquals ("000 " , TwosComplement .twosComplement ("000" ));
18- assertEquals ("00 " , TwosComplement .twosComplement ("00" ));
19- assertEquals ("0 " , TwosComplement .twosComplement ("0" ));
16+ assertEquals ("10000 " , TwosComplement .twosComplement ("0000" ));
17+ assertEquals ("1000 " , TwosComplement .twosComplement ("000" ));
18+ assertEquals ("100 " , TwosComplement .twosComplement ("00" ));
19+ assertEquals ("10 " , TwosComplement .twosComplement ("0" ));
2020 }
2121
2222 @ Test
2323 public void testTwosComplement_AllOnes () {
2424 // Test with a binary number consisting entirely of ones
25- assertEquals ("11111 " , TwosComplement .twosComplement ("11111" )); // Extra '1' due to carry
26- assertEquals ("1111 " , TwosComplement .twosComplement ("1111" ));
27- assertEquals ("111 " , TwosComplement .twosComplement ("111" ));
28- assertEquals ("11 " , TwosComplement .twosComplement ("11" ));
25+ assertEquals ("00001 " , TwosComplement .twosComplement ("11111" ));
26+ assertEquals ("0001 " , TwosComplement .twosComplement ("1111" ));
27+ assertEquals ("001 " , TwosComplement .twosComplement ("111" ));
28+ assertEquals ("01 " , TwosComplement .twosComplement ("11" ));
2929 }
3030
3131 @ Test
3232 public void testTwosComplement_MixedBits () {
3333 // Test with binary numbers with mixed bits
34- assertEquals ("1110 " , TwosComplement .twosComplement ("0001" )); // 1's complement: 1110, then add 1: 1111
34+ assertEquals ("1111 " , TwosComplement .twosComplement ("0001" )); // 1's complement: 1110, then add 1: 1111
3535 assertEquals ("1000" , TwosComplement .twosComplement ("0111" )); // 1's complement: 1000
3636 assertEquals ("11001" , TwosComplement .twosComplement ("00111" )); // 1's complement: 11000, add 1: 11001
3737 assertEquals ("011" , TwosComplement .twosComplement ("101" )); // 1's complement: 010, add 1: 011
@@ -40,22 +40,15 @@ public void testTwosComplement_MixedBits() {
4040 @ Test
4141 public void testTwosComplement_SingleBit () {
4242 // Test with single bit
43- assertEquals ("1" , TwosComplement .twosComplement ("0" ));
44- assertEquals ("11" , TwosComplement .twosComplement ("1" )); // 1's complement: 0, add 1: 1, carry generates extra
45- // '1'
46- }
47-
48- @ Test
49- public void testTwosComplement_EmptyString () {
50- // Test with an empty string
51- assertEquals ("" , TwosComplement .twosComplement ("" ));
43+ assertEquals ("10" , TwosComplement .twosComplement ("0" ));
44+ assertEquals ("11" , TwosComplement .twosComplement ("1" ));
5245 }
5346
5447 @ Test
5548 public void testTwosComplement_WithLeadingZeroes () {
5649 // Test with leading zeroes in the input
5750 assertEquals ("1111" , TwosComplement .twosComplement ("0001" ));
58- assertEquals ("100 " , TwosComplement .twosComplement ("011" ));
59- assertEquals ("101 " , TwosComplement .twosComplement ("010" ));
51+ assertEquals ("101 " , TwosComplement .twosComplement ("011" ));
52+ assertEquals ("110 " , TwosComplement .twosComplement ("010" ));
6053 }
6154}
0 commit comments