import MultiBitArray from '../../../src/statusList/multiBitArray.js'; import { Buffer } from 'buffer'; describe('MultiBitArray', () => { it('should set and get values correctly', () => { const buffer = Buffer.alloc(2); // 16 bits const mba = MultiBitArray.fromBuffer(buffer, 2); // 2 bits per entry mba.set(0, 2); // 10 mba.set(1, 1); // 01 expect(mba.get(0)).toBe(2); expect(mba.get(1)).toBe(1); }); it('should unset values', () => { const buffer = Buffer.alloc(1); // 8 bits const mba = MultiBitArray.fromBuffer(buffer, 2); mba.set(0, 3); // 11 mba.unset(0); expect(mba.get(0)).toBe(0); }); it('should throw if bitsPerEntry is not a power of 2', () => { const buffer = Buffer.alloc(1); expect(() => MultiBitArray.fromBuffer(buffer, 3)).toThrow( 'Bits must be a power of 2', ); }); it('should throw if bitsPerEntry < 1', () => { const buffer = Buffer.alloc(1); expect(() => MultiBitArray.fromBuffer(buffer, 0)).toThrow( 'Bits must be an integer >= 1', ); }); it('should throw if bitsPerEntry is not integer', () => { const buffer = Buffer.alloc(1); expect(() => MultiBitArray.fromBuffer(buffer, 1.5)).toThrow( 'Bits must be an integer >= 1', ); }); it('should convert to array', () => { const buffer = Buffer.from([0b10101010]); const mba = MultiBitArray.fromBuffer(buffer, 1); expect(Array.from(mba.toArray())).toEqual([0b10101010]); }); });