|
| 1 | +package com.thealgorithms.bitmanipulation; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.assertEquals; |
| 4 | + |
| 5 | +import org.junit.jupiter.api.Test; |
| 6 | + |
| 7 | +/** |
| 8 | + * Unit tests for the Xs3Conversion class. |
| 9 | + */ |
| 10 | +public class Xs3ConversionTest { |
| 11 | + |
| 12 | + /** |
| 13 | + * Test the xs3ToBinary method with an XS-3 number. |
| 14 | + */ |
| 15 | + @Test |
| 16 | + public void testXs3ToBinary() { |
| 17 | + int binary = Xs3Conversion.xs3ToBinary(0x4567); |
| 18 | + assertEquals(1234, binary); // XS-3 0x4567 should convert to binary 1234 |
| 19 | + } |
| 20 | + |
| 21 | + /** |
| 22 | + * Test the binaryToXs3 method with a binary number. |
| 23 | + */ |
| 24 | + @Test |
| 25 | + public void testBinaryToXs3() { |
| 26 | + int xs3 = Xs3Conversion.binaryToXs3(1234); |
| 27 | + assertEquals(0x4567, xs3); // Binary 1234 should convert to XS-3 0x4567 |
| 28 | + } |
| 29 | + |
| 30 | + /** |
| 31 | + * Test the xs3ToBinary method with zero. |
| 32 | + */ |
| 33 | + @Test |
| 34 | + public void testXs3ToBinaryZero() { |
| 35 | + int binary = Xs3Conversion.xs3ToBinary(0x0); |
| 36 | + assertEquals(0, binary); // XS-3 0x0 should convert to binary 0 |
| 37 | + } |
| 38 | + |
| 39 | + /** |
| 40 | + * Test the binaryToXs3 method with zero. |
| 41 | + */ |
| 42 | + @Test |
| 43 | + public void testBinaryToXs3Zero() { |
| 44 | + int xs3 = Xs3Conversion.binaryToXs3(0); |
| 45 | + assertEquals(0x0, xs3); // Binary 0 should convert to XS-3 0x0 |
| 46 | + } |
| 47 | + |
| 48 | + /** |
| 49 | + * Test the xs3ToBinary method with a single digit XS-3 number. |
| 50 | + */ |
| 51 | + @Test |
| 52 | + public void testXs3ToBinarySingleDigit() { |
| 53 | + int binary = Xs3Conversion.xs3ToBinary(0x5); |
| 54 | + assertEquals(2, binary); // XS-3 0x5 should convert to binary 2 |
| 55 | + } |
| 56 | + |
| 57 | + /** |
| 58 | + * Test the binaryToXs3 method with a single digit binary number. |
| 59 | + */ |
| 60 | + @Test |
| 61 | + public void testBinaryToXs3SingleDigit() { |
| 62 | + int xs3 = Xs3Conversion.binaryToXs3(2); |
| 63 | + assertEquals(0x5, xs3); // Binary 2 should convert to XS-3 0x5 |
| 64 | + } |
| 65 | +} |
0 commit comments