From 00023d7263a10fb131f930641b9d1cc61a315fa4 Mon Sep 17 00:00:00 2001 From: Sylvain Lesage Date: Fri, 20 Dec 2024 09:36:47 +0100 Subject: [PATCH] factor tests with it.for() --- test/column.test.js | 69 ++++++--------------------------------------- 1 file changed, 9 insertions(+), 60 deletions(-) diff --git a/test/column.test.js b/test/column.test.js index 7e5e20b..73f88b7 100644 --- a/test/column.test.js +++ b/test/column.test.js @@ -1,31 +1,19 @@ import { compressors } from 'hyparquet-compressors' import { describe, expect, it } from 'vitest' +import { getColumnRange, readColumn } from '../src/column.js' import { parquetMetadata } from '../src/hyparquet.js' import { getSchemaPath } from '../src/schema.js' -import { getColumnRange, readColumn } from '../src/column.js' import { asyncBufferFromFile } from '../src/utils.js' -describe('readColumn', () => { - it('read columns when rowLimit is undefined', async () => { - const testFile = 'test/files/float16_nonzeros_and_nans.parquet' - const asyncBuffer = await asyncBufferFromFile(testFile) - const arrayBuffer = await asyncBuffer.slice(0) - const metadata = parquetMetadata(arrayBuffer) +const values = [null, 1, -2, NaN, 0, -1, -0, 2] - const column = metadata.row_groups[0].columns[0] - if (!column.meta_data) throw new Error(`No column metadata for ${testFile}`) - const [columnStartByte, columnEndByte] = getColumnRange(column.meta_data).map(Number) - const columnArrayBuffer = arrayBuffer.slice(columnStartByte, columnEndByte) - const schemaPath = getSchemaPath(metadata.schema, column.meta_data?.path_in_schema ?? []) - const reader = { view: new DataView(columnArrayBuffer), offset: 0 } - - const rowLimit = undefined - const result = readColumn(reader, rowLimit, column.meta_data, schemaPath, { file: asyncBuffer, compressors }) - const expected = [null, 1, -2, NaN, 0, -1, -0, 2] - expect(result).toEqual(expected) - }) - - it('read columns when rowLimit is Infinity', async () => { +describe('readColumn', () => { + it.for([ + { rowLimit: undefined, expected: values }, + { rowLimit: Infinity, expected: values }, + { rowLimit: 2, expected: values.slice(0, 2) }, + { rowLimit: 0, expected: [] }, + ])('readColumn with rowLimit %p', async ({ rowLimit, expected }) => { const testFile = 'test/files/float16_nonzeros_and_nans.parquet' const asyncBuffer = await asyncBufferFromFile(testFile) const arrayBuffer = await asyncBuffer.slice(0) @@ -38,46 +26,7 @@ describe('readColumn', () => { const schemaPath = getSchemaPath(metadata.schema, column.meta_data?.path_in_schema ?? []) const reader = { view: new DataView(columnArrayBuffer), offset: 0 } - const rowLimit = Infinity const result = readColumn(reader, rowLimit, column.meta_data, schemaPath, { file: asyncBuffer, compressors }) - const expected = [null, 1, -2, NaN, 0, -1, -0, 2] expect(result).toEqual(expected) }) - - it('read columns when rowLimit is defined', async () => { - const testFile = 'test/files/float16_nonzeros_and_nans.parquet' - const asyncBuffer = await asyncBufferFromFile(testFile) - const arrayBuffer = await asyncBuffer.slice(0) - const metadata = parquetMetadata(arrayBuffer) - - const column = metadata.row_groups[0].columns[0] - if (!column.meta_data) throw new Error(`No column metadata for ${testFile}`) - const [columnStartByte, columnEndByte] = getColumnRange(column.meta_data).map(Number) - const columnArrayBuffer = arrayBuffer.slice(columnStartByte, columnEndByte) - const schemaPath = getSchemaPath(metadata.schema, column.meta_data?.path_in_schema ?? []) - const reader = { view: new DataView(columnArrayBuffer), offset: 0 } - - const rowLimit = 2 - const result = readColumn(reader, rowLimit, column.meta_data, schemaPath, { file: asyncBuffer, compressors }) - expect(result.length).toBe(rowLimit) - }) - - it('read columns when rowLimit is 0', async () => { - const testFile = 'test/files/float16_nonzeros_and_nans.parquet' - const asyncBuffer = await asyncBufferFromFile(testFile) - const arrayBuffer = await asyncBuffer.slice(0) - const metadata = parquetMetadata(arrayBuffer) - - const column = metadata.row_groups[0].columns[0] - if (!column.meta_data) throw new Error(`No column metadata for ${testFile}`) - const [columnStartByte, columnEndByte] = getColumnRange(column.meta_data).map(Number) - const columnArrayBuffer = arrayBuffer.slice(columnStartByte, columnEndByte) - const schemaPath = getSchemaPath(metadata.schema, column.meta_data?.path_in_schema ?? []) - const reader = { view: new DataView(columnArrayBuffer), offset: 0 } - - const rowLimit = 0 - const result = readColumn(reader, rowLimit, column.meta_data, schemaPath, { file: asyncBuffer, compressors }) - expect(result.length).toBe(rowLimit) - }) - })