let values: string[] = []; const huffman = new HuffmanCode(); for (let i = 0; i < 100; i ++) { for (let j = 0; j < Math.round(Math.random() * 200) + 10; j ++) { // Only string is allowed huffman.add(i.toString()); values.push(i.toString()); }} // Build huffman code treehuffman.build(); for (let i = 0; i < 100; i ++) { it(`should decode ${i}`, () => { // Encode const encoded = huffman.encode(i.toString()); // Decode const decoded = huffman.decode(encoded)[0]; expect(decoded).toEqual(i.toString()); })} it('should decode array', () => { const raw: string[] = []; for (let i = 0; i < 100; i ++) { raw.push(Math.min(99, Math.floor(Math.random() * 100)).toString()); } let encoded = ""; raw.forEach(r => { const e = huffman.encode(r); encoded += e; }) // Decode consecutive huffman code binary string const decoded = huffman.decode(encoded); expect(decoded).toEqual(raw);}) it('should get bit size', () => { let expected = 0; values.forEach(value => { expected += huffman.encode(value).length; }) // Get size of bits expect(huffman.bitSize()).toEqual(expected);})
huffman-code
1.0.2 • Public • Published; ; for ; i < 100; i ++ // Build huffman code treehuffman.build; for ; i < 100; i ++ it'should decode array', it'should get bit size',
Readme
Keywords
nonePackage Sidebar
Install
npm i huffman-code
Repository
Weekly Downloads
2
Version
1.0.2
License
ISC
Unpacked Size
10.5 kB
Total Files
10