|
| 1 | +import { binaryArrayToDecimal } from "../convert"; |
| 2 | + |
| 3 | +describe("Util - Convert", () => { |
| 4 | + describe("binaryArrayToDecimal method", () => { |
| 5 | + test("converts a byte successfully (00000000)", () => { |
| 6 | + const input = [0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0, 0b0]; |
| 7 | + const result = binaryArrayToDecimal(input); |
| 8 | + expect(result).toBe(0); |
| 9 | + }); |
| 10 | + |
| 11 | + test("converts a byte successfully (11111111)", () => { |
| 12 | + const input = [0b1, 0b1, 0b1, 0b1, 0b1, 0b1, 0b1, 0b1]; |
| 13 | + const result = binaryArrayToDecimal(input); |
| 14 | + expect(result).toBe(255); |
| 15 | + }); |
| 16 | + |
| 17 | + test("converts a byte successfully (10101010)", () => { |
| 18 | + const input = [0b1, 0b0, 0b1, 0b0, 0b1, 0b0, 0b1, 0b0]; |
| 19 | + const result = binaryArrayToDecimal(input); |
| 20 | + expect(result).toBe(170); |
| 21 | + }); |
| 22 | + |
| 23 | + test("converts a byte successfully (01010101)", () => { |
| 24 | + const input = [0b0, 0b1, 0b0, 0b1, 0b0, 0b1, 0b0, 0b1]; |
| 25 | + const result = binaryArrayToDecimal(input); |
| 26 | + expect(result).toBe(85); |
| 27 | + }); |
| 28 | + |
| 29 | + test("converts a nibble successfully (0100)", () => { |
| 30 | + const input = [0b0, 0b1, 0b0, 0b0]; |
| 31 | + const result = binaryArrayToDecimal(input); |
| 32 | + expect(result).toBe(4); |
| 33 | + }); |
| 34 | + |
| 35 | + test("converts a nibble successfully (1100)", () => { |
| 36 | + const input = [0b1, 0b1, 0b0, 0b0]; |
| 37 | + const result = binaryArrayToDecimal(input); |
| 38 | + expect(result).toBe(12); |
| 39 | + }); |
| 40 | + }); |
| 41 | +}); |
0 commit comments