Encoding readRleBitPackedHybrid tests

This commit is contained in:
Kenny Daniel 2024-01-14 19:40:39 -08:00
parent 00a8dbf57f
commit a5a9824715
No known key found for this signature in database
GPG Key ID: 6A3C5E318BE71391
2 changed files with 34 additions and 3 deletions

@ -226,7 +226,7 @@ export function readData(dataView, encoding, offset, count, bitWidth) {
* @param {DataView} dataView - buffer to read data from
* @param {number} offset - offset to start reading from the DataView
* @param {number} width - width of each bit-packed group
* @param {number} length - length of the encoded data
* @param {number | undefined} length - length of the encoded data
* @param {number} numValues - number of values to read
* @returns {Decoded<number[]>} array of rle/bit-packed values
*/

@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest'
import { ParquetType } from '../src/constants.js'
import { readPlain } from '../src/encoding.js'
import { readPlain, readRleBitPackedHybrid } from '../src/encoding.js'
describe('readPlain', () => {
@ -90,4 +90,35 @@ describe('readPlain', () => {
})
})
// TODO: Add tests for readData
describe('readRleBitPackedHybrid', () => {
it('reads RLE bit-packed hybrid values with explicit length', () => {
// Example buffer: 1 RLE group followed by 1 bit-packed group
// RLE values: true x3
// Bit-packed values: false, false, true
const buffer = new ArrayBuffer(4)
const dataView = new DataView(buffer)
dataView.setUint8(0, 0b00000110) // RLE header for 3 true values
dataView.setUint8(1, 0b00000001) // RLE value (true)
dataView.setUint8(2, 0b00000011) // Bit-packed header for 3 values
dataView.setUint8(3, 0b00000100) // Bit-packed values (false, false, true)
const { byteLength, value } = readRleBitPackedHybrid(dataView, 0, 1, 3, 6)
expect(byteLength).toBe(4)
expect(value).toEqual([1, 1, 1, 0, 0, 1])
})
it('reads RLE bit-packed hybrid values with implicit length', () => {
// Example buffer: same as previous test, but with implicit length
const buffer = new ArrayBuffer(8)
const dataView = new DataView(buffer)
dataView.setInt32(0, 3, true) // length 3 little-endian
dataView.setUint8(4, 0b00000110) // RLE header for 3 true values
dataView.setUint8(5, 0b00000001) // RLE value (true)
dataView.setUint8(6, 0b00000011) // Bit-packed header for 3 values
dataView.setUint8(7, 0b00000100) // Bit-packed values (false, false, true)
const { byteLength, value } = readRleBitPackedHybrid(dataView, 0, 1, undefined, 6)
expect(byteLength).toBe(8)
expect(value).toEqual([1, 1, 1, 0, 0, 1])
})
})