From 9bfefecf0af9c13787e57580fc8aa503c54b60f9 Mon Sep 17 00:00:00 2001 From: jobo322 Date: Thu, 4 Dec 2025 09:16:37 -0500 Subject: [PATCH 1/5] fix: keep input type in reimZeroFilling --- src/reim/reimZeroFilling.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/reim/reimZeroFilling.ts b/src/reim/reimZeroFilling.ts index d9ed9190..a54a1cec 100644 --- a/src/reim/reimZeroFilling.ts +++ b/src/reim/reimZeroFilling.ts @@ -1,3 +1,5 @@ +import type { DoubleArray } from 'cheminfo-types'; + import type { DataReIm } from '../types/index.ts'; /** @@ -8,7 +10,10 @@ import type { DataReIm } from '../types/index.ts'; * truncated arrays if totalLength is smaller current length or * the same input if totalLength is equal that current length */ -export function reimZeroFilling(data: DataReIm, totalLength: number): DataReIm { +export function reimZeroFilling( + data: DataReIm, + totalLength: number, +): DataReIm> { if (!Number.isInteger(totalLength) || totalLength < 0) { throw new RangeError('totalLength must be a non-negative integer'); } @@ -20,8 +25,8 @@ export function reimZeroFilling(data: DataReIm, totalLength: number): DataReIm { if (length > totalLength) { return { - re: re.slice(0, totalLength), - im: im.slice(0, totalLength), + re: re.slice(0, totalLength) as ArrayType, + im: im.slice(0, totalLength) as ArrayType, }; } From f51d57f57946fddb7dcb502fed9933f5accbb6a6 Mon Sep 17 00:00:00 2001 From: jobo322 Date: Thu, 4 Dec 2025 09:28:02 -0500 Subject: [PATCH 2/5] chore: fix eslint in test cases --- .../__tests__/matrixAutoCorrelation.test.ts | 2 +- src/matrix/__tests__/matrixBoxPlot.test.ts | 2 +- src/matrix/__tests__/matrixCheck.test.ts | 2 +- .../__tests__/matrixCheckRanges.test.ts | 4 +-- .../__tests__/matrixGetSubMatrix.test.ts | 2 +- .../__tests__/matrixMaxAbsoluteZ.test.ts | 2 +- .../__tests__/matrixMinMaxAbsoluteZ.test.ts | 2 +- src/matrix/__tests__/matrixMinMaxZ.test.ts | 2 +- .../__tests__/matrixSetSubMatrix.test.ts | 4 +-- src/reim/__tests__/reimZeroFilling.test.ts | 4 +-- src/utils/__tests__/createFromToArray.test.ts | 2 +- src/utils/__tests__/getRescaler.test.ts | 2 +- src/x/__tests__/xBoxPlot.test.ts | 2 +- src/x/__tests__/xCheck.test.ts | 8 ++--- src/x/__tests__/xDistributionStats.test.ts | 4 ++- src/x/__tests__/xMeanAbsoluteError.test.ts | 2 +- src/x/__tests__/xMeanSquaredError.test.ts | 2 +- src/x/__tests__/xMeanWeighted.test.ts | 4 +-- src/x/__tests__/xMedian.test.ts | 2 +- src/x/__tests__/xMode.test.ts | 2 +- src/x/__tests__/xNormed.test.ts | 30 +++++++++---------- src/x/__tests__/xRescale.test.ts | 12 ++++---- .../xRobustDistributionStats.test.ts | 2 +- src/x/__tests__/xRolling.test.ts | 2 +- src/x/__tests__/xStandardDeviation.test.ts | 4 ++- src/xy/__tests__/xyAlign.test.ts | 2 +- src/xy/__tests__/xyCheck.test.ts | 10 ++++--- src/xy/__tests__/xyEquallySpaced.test.ts | 10 +++---- src/xy/__tests__/xyGetNMaxY.test.ts | 2 +- src/xy/__tests__/xyIntegral.test.ts | 2 +- src/xy/__tests__/xyIntegration.test.ts | 2 +- src/xy/__tests__/xyMassCenter.test.ts | 6 ++-- src/xy/__tests__/xyRolling.test.ts | 2 +- .../xyRollingCircleTransform.test.ts | 2 +- src/xyObject/__tests__/xyObjectCheck.test.ts | 6 ++-- .../__tests__/xyObjectMinMaxValues.test.ts | 2 +- 36 files changed, 79 insertions(+), 73 deletions(-) diff --git a/src/matrix/__tests__/matrixAutoCorrelation.test.ts b/src/matrix/__tests__/matrixAutoCorrelation.test.ts index a29ed54f..081a086a 100644 --- a/src/matrix/__tests__/matrixAutoCorrelation.test.ts +++ b/src/matrix/__tests__/matrixAutoCorrelation.test.ts @@ -17,7 +17,7 @@ test('simple', () => { test('matrixAutoCorrelation too small', () => { const matrix = [[0]]; - expect(() => matrixAutoCorrelation(matrix)).toThrow( + expect(() => matrixAutoCorrelation(matrix)).toThrowError( 'can not calculate info if matrix contains less than 2 rows', ); }); diff --git a/src/matrix/__tests__/matrixBoxPlot.test.ts b/src/matrix/__tests__/matrixBoxPlot.test.ts index 0b865b48..108828fb 100644 --- a/src/matrix/__tests__/matrixBoxPlot.test.ts +++ b/src/matrix/__tests__/matrixBoxPlot.test.ts @@ -66,7 +66,7 @@ test('matrixBoxPlot odd small', () => { test('matrixBoxPlot too small', () => { const matrix = [[0], [1], [2], [4]]; - expect(() => matrixBoxPlot(matrix)).toThrow( + expect(() => matrixBoxPlot(matrix)).toThrowError( 'can not calculate info if matrix contains less than 5 rows', ); }); diff --git a/src/matrix/__tests__/matrixCheck.test.ts b/src/matrix/__tests__/matrixCheck.test.ts index a71cfab3..649fbbc3 100644 --- a/src/matrix/__tests__/matrixCheck.test.ts +++ b/src/matrix/__tests__/matrixCheck.test.ts @@ -8,7 +8,7 @@ test('should throw error', () => { [3, 2, 3], ]; - expect(() => matrixCheck(wrongMatrix)).toThrow( + expect(() => matrixCheck(wrongMatrix)).toThrowError( 'all rows must has the same length', ); }); diff --git a/src/matrix/__tests__/matrixCheckRanges.test.ts b/src/matrix/__tests__/matrixCheckRanges.test.ts index 6d59c824..7a02863e 100644 --- a/src/matrix/__tests__/matrixCheckRanges.test.ts +++ b/src/matrix/__tests__/matrixCheckRanges.test.ts @@ -18,7 +18,7 @@ test('should not throw error for valid indices', () => { endColumn: 2, }; - expect(() => matrixCheckRanges(matrix, options)).not.toThrow(); + expect(() => matrixCheckRanges(matrix, options)).not.toThrowError(); }); test('should throw RangeError for out-of-range indices', () => { @@ -38,5 +38,5 @@ test('should throw RangeError for out-of-range indices', () => { }; // Call the function and expect test to throw RangeError - expect(() => matrixCheckRanges(matrix, options)).toThrow(RangeError); + expect(() => matrixCheckRanges(matrix, options)).toThrowError(RangeError); }); diff --git a/src/matrix/__tests__/matrixGetSubMatrix.test.ts b/src/matrix/__tests__/matrixGetSubMatrix.test.ts index 4c03208d..e022199f 100644 --- a/src/matrix/__tests__/matrixGetSubMatrix.test.ts +++ b/src/matrix/__tests__/matrixGetSubMatrix.test.ts @@ -64,5 +64,5 @@ test('should throw RangeError for out-of-range indices', () => { duplicate: true, }; - expect(() => matrixGetSubMatrix(matrix, options)).toThrow(RangeError); + expect(() => matrixGetSubMatrix(matrix, options)).toThrowError(RangeError); }); diff --git a/src/matrix/__tests__/matrixMaxAbsoluteZ.test.ts b/src/matrix/__tests__/matrixMaxAbsoluteZ.test.ts index 1056611d..2f01719a 100644 --- a/src/matrix/__tests__/matrixMaxAbsoluteZ.test.ts +++ b/src/matrix/__tests__/matrixMaxAbsoluteZ.test.ts @@ -27,5 +27,5 @@ test('large negative', () => { test('zero', () => { expect(() => { matrixMaxAbsoluteZ([[]]); - }).toThrow('matrix must have at least 1 row and 1 column'); + }).toThrowError('matrix must have at least 1 row and 1 column'); }); diff --git a/src/matrix/__tests__/matrixMinMaxAbsoluteZ.test.ts b/src/matrix/__tests__/matrixMinMaxAbsoluteZ.test.ts index 35f3553f..5d9ff710 100644 --- a/src/matrix/__tests__/matrixMinMaxAbsoluteZ.test.ts +++ b/src/matrix/__tests__/matrixMinMaxAbsoluteZ.test.ts @@ -18,5 +18,5 @@ test('zero', () => { expect(() => { matrixMinMaxAbsoluteZ(matrix); - }).toThrow('matrixMinMaxAbsoluteZ requires at least 1 row and 1 column'); + }).toThrowError('matrixMinMaxAbsoluteZ requires at least 1 row and 1 column'); }); diff --git a/src/matrix/__tests__/matrixMinMaxZ.test.ts b/src/matrix/__tests__/matrixMinMaxZ.test.ts index 46f20b5e..9f8d0a56 100644 --- a/src/matrix/__tests__/matrixMinMaxZ.test.ts +++ b/src/matrix/__tests__/matrixMinMaxZ.test.ts @@ -16,5 +16,5 @@ test('basic', () => { test('zero', () => { expect(() => { matrixMinMaxZ([[]]); - }).toThrow('matrix must contain data'); + }).toThrowError('matrix must contain data'); }); diff --git a/src/matrix/__tests__/matrixSetSubMatrix.test.ts b/src/matrix/__tests__/matrixSetSubMatrix.test.ts index 2cf611c2..f54eeb2a 100644 --- a/src/matrix/__tests__/matrixSetSubMatrix.test.ts +++ b/src/matrix/__tests__/matrixSetSubMatrix.test.ts @@ -24,11 +24,11 @@ test('simple case', () => { [3, 4, 5, 0, 0], ]); - expect(() => matrixSetSubMatrix(matrix, subMatrix, 2, 4)).toThrow( + expect(() => matrixSetSubMatrix(matrix, subMatrix, 2, 4)).toThrowError( 'submatrix indices are out of range', ); expect(() => matrixSetSubMatrix(matrix, subMatrix.concat([0, 0]), 2, 3), - ).toThrow('submatrix indices are out of range'); + ).toThrowError('submatrix indices are out of range'); }); diff --git a/src/reim/__tests__/reimZeroFilling.test.ts b/src/reim/__tests__/reimZeroFilling.test.ts index 11151afe..4b4eea88 100644 --- a/src/reim/__tests__/reimZeroFilling.test.ts +++ b/src/reim/__tests__/reimZeroFilling.test.ts @@ -30,8 +30,8 @@ test('xreimZeroFilling equal', () => { }); test('xreimZeroFilling under', () => { - const re = [0, 1, 2, 3]; - const im = [4, 5, 6, 7]; + const re = new Float64Array([0, 1, 2, 3]); + const im = new Float64Array([4, 5, 6, 7]); const result = reimZeroFilling({ re, im }, 2); const newRe = Array.from(result.re); const newIm = Array.from(result.im); diff --git a/src/utils/__tests__/createFromToArray.test.ts b/src/utils/__tests__/createFromToArray.test.ts index f8c9d0a4..c56e3a34 100644 --- a/src/utils/__tests__/createFromToArray.test.ts +++ b/src/utils/__tests__/createFromToArray.test.ts @@ -112,5 +112,5 @@ test('case when we choose a distribution other than uniform or log', () => { // @ts-expect-error Testing bad argument. distribution: 'other', }); - }).toThrow(Error); + }).toThrowError(Error); }); diff --git a/src/utils/__tests__/getRescaler.test.ts b/src/utils/__tests__/getRescaler.test.ts index 732246a2..2a338868 100644 --- a/src/utils/__tests__/getRescaler.test.ts +++ b/src/utils/__tests__/getRescaler.test.ts @@ -37,7 +37,7 @@ test('getRescale with wrong min / max, no clamp', () => { clamp: false, }); - expect(() => rescaler(2)).toThrow('Value 2 is out of range [0, 1]'); + expect(() => rescaler(2)).toThrowError('Value 2 is out of range [0, 1]'); }); test('getRescale with wrong min / max and logartihmic', () => { diff --git a/src/x/__tests__/xBoxPlot.test.ts b/src/x/__tests__/xBoxPlot.test.ts index 99077eac..58815faf 100644 --- a/src/x/__tests__/xBoxPlot.test.ts +++ b/src/x/__tests__/xBoxPlot.test.ts @@ -92,7 +92,7 @@ test('xBoxPlot odd small', () => { test('xBoxPlot too small', () => { const array: number[] = []; - expect(() => xBoxPlot(array)).toThrow('input must not be empty'); + expect(() => xBoxPlot(array)).toThrowError('input must not be empty'); }); test('xBoxPlot with one element', () => { diff --git a/src/x/__tests__/xCheck.test.ts b/src/x/__tests__/xCheck.test.ts index 9da51610..c04e074c 100644 --- a/src/x/__tests__/xCheck.test.ts +++ b/src/x/__tests__/xCheck.test.ts @@ -3,10 +3,10 @@ import { expect, test } from 'vitest'; import { xCheck } from '../xCheck.ts'; test('should throw on invalid value', () => { - expect(() => xCheck()).toThrow(/input must be an array/); - expect(() => xCheck([])).toThrow(/input must not be empty/); - expect(() => xCheck([1])).not.toThrow(); - expect(() => xCheck([1], { minLength: 2 })).toThrow( + expect(() => xCheck()).toThrowError(/input must be an array/); + expect(() => xCheck([])).toThrowError(/input must not be empty/); + expect(() => xCheck([1])).not.toThrowError(); + expect(() => xCheck([1], { minLength: 2 })).toThrowError( /input must have a length of at least 2/, ); }); diff --git a/src/x/__tests__/xDistributionStats.test.ts b/src/x/__tests__/xDistributionStats.test.ts index 451ab45a..62fccc2a 100644 --- a/src/x/__tests__/xDistributionStats.test.ts +++ b/src/x/__tests__/xDistributionStats.test.ts @@ -5,7 +5,9 @@ import { xDistributionStats } from '../xDistributionStats.ts'; test('empty array', () => { const data: number[] = []; - expect(() => xDistributionStats(data)).toThrow('input must not be empty'); + expect(() => xDistributionStats(data)).toThrowError( + 'input must not be empty', + ); }); test('one element', () => { diff --git a/src/x/__tests__/xMeanAbsoluteError.test.ts b/src/x/__tests__/xMeanAbsoluteError.test.ts index 82e80bb2..9a9511c0 100644 --- a/src/x/__tests__/xMeanAbsoluteError.test.ts +++ b/src/x/__tests__/xMeanAbsoluteError.test.ts @@ -21,5 +21,5 @@ test('different length', () => { expect(() => { return xMeanAbsoluteError(array1, array2); - }).toThrow(/length of array1 and array2 must be identical/); + }).toThrowError(/length of array1 and array2 must be identical/); }); diff --git a/src/x/__tests__/xMeanSquaredError.test.ts b/src/x/__tests__/xMeanSquaredError.test.ts index 592ac253..49069138 100644 --- a/src/x/__tests__/xMeanSquaredError.test.ts +++ b/src/x/__tests__/xMeanSquaredError.test.ts @@ -21,5 +21,5 @@ test('different length', () => { expect(() => { return xMeanSquaredError(array1, array2); - }).toThrow(/length of array1 and array2 must be identical/); + }).toThrowError(/length of array1 and array2 must be identical/); }); diff --git a/src/x/__tests__/xMeanWeighted.test.ts b/src/x/__tests__/xMeanWeighted.test.ts index 50479cff..98aa9642 100644 --- a/src/x/__tests__/xMeanWeighted.test.ts +++ b/src/x/__tests__/xMeanWeighted.test.ts @@ -30,10 +30,10 @@ test('xMeanWeighted', () => { xMeanWeighted([3, 2, 1], [1, 1, 1], { fromIndex: 1, toIndex: 1 }), ).toBe(2); // expect to throw an error if the length of the arrays are not the same - expect(() => xMeanWeighted([1, 2, 3], [1, 1])).toThrow( + expect(() => xMeanWeighted([1, 2, 3], [1, 1])).toThrowError( 'array and weights must have the same length', ); - expect(() => xMeanWeighted([1, 2, 3], [0, 0, 0])).toThrow( + expect(() => xMeanWeighted([1, 2, 3], [0, 0, 0])).toThrowError( 'sum of weights must be > 0', ); }); diff --git a/src/x/__tests__/xMedian.test.ts b/src/x/__tests__/xMedian.test.ts index 74ddafbc..7daf183c 100644 --- a/src/x/__tests__/xMedian.test.ts +++ b/src/x/__tests__/xMedian.test.ts @@ -31,5 +31,5 @@ test('should return the median with typed array', () => { }); test('should throw on invalid value', () => { - expect(() => xMedian([])).toThrow(/input must not be empty/); + expect(() => xMedian([])).toThrowError(/input must not be empty/); }); diff --git a/src/x/__tests__/xMode.test.ts b/src/x/__tests__/xMode.test.ts index 968a3b29..94b76701 100644 --- a/src/x/__tests__/xMode.test.ts +++ b/src/x/__tests__/xMode.test.ts @@ -18,5 +18,5 @@ test('should return the mode', () => { }); test('should throw on invalid value', () => { - expect(() => xMode([])).toThrow(/input must not be empty/); + expect(() => xMode([])).toThrowError(/input must not be empty/); }); diff --git a/src/x/__tests__/xNormed.test.ts b/src/x/__tests__/xNormed.test.ts index 300adf03..07c2e436 100644 --- a/src/x/__tests__/xNormed.test.ts +++ b/src/x/__tests__/xNormed.test.ts @@ -5,10 +5,10 @@ import { xNormed } from '../xNormed.ts'; test('should return the norm', () => { expect(() => { xNormed([0]); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(() => { xNormed([0, 0]); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(xNormed([-1, 1])).toStrictEqual(Float64Array.from([-0.5, 0.5])); expect(xNormed([1, 3])).toStrictEqual(Float64Array.from([0.25, 0.75])); }); @@ -16,10 +16,10 @@ test('should return the norm', () => { test('should return the norm algorithm=absolute', () => { expect(() => { xNormed([0], { algorithm: 'absolute' }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(() => { xNormed([0, 0], { algorithm: 'absolute' }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(xNormed([-1, 1], { algorithm: 'absolute' })).toStrictEqual( Float64Array.from([-0.5, 0.5]), ); @@ -31,10 +31,10 @@ test('should return the norm algorithm=absolute', () => { test('should return the norm algorithm=max', () => { expect(() => { xNormed([0], { algorithm: 'max' }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(() => { xNormed([0, 0], { algorithm: 'max' }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(xNormed([-1, 1], { algorithm: 'max' })).toStrictEqual( Float64Array.from([-1, 1]), ); @@ -46,10 +46,10 @@ test('should return the norm algorithm=max', () => { test('should return the norm algorithm=max and max to 100', () => { expect(() => { xNormed([0], { algorithm: 'max', value: 100 }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(() => { xNormed([0, 0], { algorithm: 'max', value: 100 }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(xNormed([-1, 1], { algorithm: 'max', value: 100 })).toStrictEqual( Float64Array.from([-100, 100]), @@ -62,13 +62,13 @@ test('should return the norm algorithm=max and max to 100', () => { test('should return the norm algorithm=sum', () => { expect(() => { xNormed([0], { algorithm: 'sum' }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(() => { xNormed([0, 0], { algorithm: 'sum' }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(() => { xNormed([-1, 1], { algorithm: 'sum' }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(xNormed([-1, 3], { algorithm: 'sum' })).toStrictEqual( Float64Array.from([-0.5, 1.5]), ); @@ -80,13 +80,13 @@ test('should return the norm algorithm=sum', () => { test('should return the norm algorithm=sum sumValue=5', () => { expect(() => { xNormed([0], { algorithm: 'sum', value: 5 }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(() => { xNormed([0, 0], { algorithm: 'sum', value: 5 }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(() => { xNormed([-1, 1], { algorithm: 'sum', value: 5 }); - }).toThrow('trying to divide by 0'); + }).toThrowError('trying to divide by 0'); expect(xNormed([-1, 3], { algorithm: 'sum', value: 5 })).toStrictEqual( Float64Array.from([-2.5, 7.5]), ); @@ -96,5 +96,5 @@ test('should return the norm algorithm=sum sumValue=5', () => { }); test('should throw on invalid value', () => { - expect(() => xNormed([])).toThrow(/input must not be empty/); + expect(() => xNormed([])).toThrowError(/input must not be empty/); }); diff --git a/src/x/__tests__/xRescale.test.ts b/src/x/__tests__/xRescale.test.ts index ee3b13cb..6c32bd65 100644 --- a/src/x/__tests__/xRescale.test.ts +++ b/src/x/__tests__/xRescale.test.ts @@ -15,7 +15,7 @@ test('should return a rescaled array', () => { }); test('should throw min == max', () => { - expect(() => xRescale([1, 1])).toThrow( + expect(() => xRescale([1, 1])).toThrowError( /minimum and maximum input values are equal\. Cannot rescale a constant array/, ); }); @@ -58,19 +58,19 @@ test('should work with custom min/max', () => { }); test('should throw on bad inputs', () => { - expect(() => xRescale([0, 1, 2], { min: 2 })).toThrow( + expect(() => xRescale([0, 1, 2], { min: 2 })).toThrowError( /min option must be smaller than max option/, ); - expect(() => xRescale([0, 1, 2], { max: -1 })).toThrow( + expect(() => xRescale([0, 1, 2], { max: -1 })).toThrowError( /min option must be smaller than max option/, ); - expect(() => xRescale([0, 1, 2], { min: 2, max: 0 })).toThrow( + expect(() => xRescale([0, 1, 2], { min: 2, max: 0 })).toThrowError( /min option must be smaller than max option/, ); - expect(() => xRescale([0, 1, 2], { min: 1, max: 1 })).toThrow( + expect(() => xRescale([0, 1, 2], { min: 1, max: 1 })).toThrowError( /min option must be smaller than max option/, ); - expect(() => xRescale([], { min: 0, max: 1 })).toThrow( + expect(() => xRescale([], { min: 0, max: 1 })).toThrowError( /input must not be empty/, ); }); diff --git a/src/x/__tests__/xRobustDistributionStats.test.ts b/src/x/__tests__/xRobustDistributionStats.test.ts index 111fc0b6..9d9b4651 100644 --- a/src/x/__tests__/xRobustDistributionStats.test.ts +++ b/src/x/__tests__/xRobustDistributionStats.test.ts @@ -5,7 +5,7 @@ import { xRobustDistributionStats } from '../xRobustDistributionStats.ts'; test('empty array', () => { const data: number[] = []; - expect(() => xRobustDistributionStats(data)).toThrow( + expect(() => xRobustDistributionStats(data)).toThrowError( 'input must not be empty', ); }); diff --git a/src/x/__tests__/xRolling.test.ts b/src/x/__tests__/xRolling.test.ts index 7bbbaef2..a756e8c6 100644 --- a/src/x/__tests__/xRolling.test.ts +++ b/src/x/__tests__/xRolling.test.ts @@ -5,7 +5,7 @@ import { xRolling } from '../xRolling.ts'; test('xRolling', () => { const array = [1, 2, 3, 4, 5, 6, 7, 8, 9]; - expect(() => xRolling(array)).toThrow('fct must be a function'); + expect(() => xRolling(array)).toThrowError('fct must be a function'); expect(xRolling(array, () => 1, { window: 5 })).toStrictEqual([ 1, 1, 1, 1, 1, ]); diff --git a/src/x/__tests__/xStandardDeviation.test.ts b/src/x/__tests__/xStandardDeviation.test.ts index bcb5e3d2..cda0c014 100644 --- a/src/x/__tests__/xStandardDeviation.test.ts +++ b/src/x/__tests__/xStandardDeviation.test.ts @@ -31,5 +31,7 @@ test('one element', () => { test('empty array', () => { const data: number[] = []; - expect(() => xStandardDeviation(data)).toThrow('input must not be empty'); + expect(() => xStandardDeviation(data)).toThrowError( + 'input must not be empty', + ); }); diff --git a/src/xy/__tests__/xyAlign.test.ts b/src/xy/__tests__/xyAlign.test.ts index 96779b03..a32d963a 100644 --- a/src/xy/__tests__/xyAlign.test.ts +++ b/src/xy/__tests__/xyAlign.test.ts @@ -119,7 +119,7 @@ test('should throw unknown option x', () => { const data2 = { x: [2, 3, 4], y: [1, 1, 1] }; // @ts-expect-error Testing wrong option. - expect(() => xyAlign(data1, data2, { x: 'hey' })).toThrow( + expect(() => xyAlign(data1, data2, { x: 'hey' })).toThrowError( 'unknown x option value: hey', ); }); diff --git a/src/xy/__tests__/xyCheck.test.ts b/src/xy/__tests__/xyCheck.test.ts index cef15748..44e80efe 100644 --- a/src/xy/__tests__/xyCheck.test.ts +++ b/src/xy/__tests__/xyCheck.test.ts @@ -4,12 +4,14 @@ import { xyCheck } from '../xyCheck.ts'; test('various kind of object', () => { //@ts-expect-error We are testing that it throws correctly an error - expect(() => xyCheck()).toThrow('data must be an object'); - expect(() => xyCheck({ x: [], z: [] })).toThrow('data must be an object'); - expect(() => xyCheck({ x: [], y: [] }, { minLength: 1 })).toThrow( + expect(() => xyCheck()).toThrowError('data must be an object'); + expect(() => xyCheck({ x: [], z: [] })).toThrowError( + 'data must be an object', + ); + expect(() => xyCheck({ x: [], y: [] }, { minLength: 1 })).toThrowError( 'data.x must have a length of at least 1', ); - expect(() => xyCheck({ x: [1], y: [1, 2] })).toThrow( + expect(() => xyCheck({ x: [1], y: [1, 2] })).toThrowError( 'the x and y arrays must have the same length', ); expect(xyCheck({ x: [1], y: [1] })).toBeUndefined(); diff --git a/src/xy/__tests__/xyEquallySpaced.test.ts b/src/xy/__tests__/xyEquallySpaced.test.ts index 27f6990e..d8fa0406 100644 --- a/src/xy/__tests__/xyEquallySpaced.test.ts +++ b/src/xy/__tests__/xyEquallySpaced.test.ts @@ -38,7 +38,7 @@ test('testing 1 points', () => { numberOfPoints: 1, }, ), - ).toThrow('greater than 1'); + ).toThrowError('greater than 1'); }); test('large file should not be slow', () => { @@ -68,7 +68,7 @@ test('non growing', () => { numberOfPoints: 5, }, ), - ).toThrow('x must be a growing series'); + ).toThrowError('x must be a growing series'); }); test('equallySpaced smooth', () => { @@ -204,7 +204,7 @@ test('equallySpaced slot', () => { variant: 'slot', }, ); - }).toThrow('x must be a growing series'); + }).toThrowError('x must be a growing series'); x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; y = [0, 1, 2, 3, 4, 5, 4, 3, 2, 1, 0]; @@ -238,7 +238,7 @@ test('changing from and to', () => { variant: 'smooth', }, ); - }).toThrow('from should be larger than to'); + }).toThrowError('from should be larger than to'); }); test('testing exclusions', () => { @@ -277,7 +277,7 @@ test('testing inverted exclusions', () => { exclusions: [{ from: 7, to: 2 }], }, ); - }).toThrow('from should be larger than to'); + }).toThrowError('from should be larger than to'); }); test('testing zones', () => { diff --git a/src/xy/__tests__/xyGetNMaxY.test.ts b/src/xy/__tests__/xyGetNMaxY.test.ts index e48197cf..877b85d8 100644 --- a/src/xy/__tests__/xyGetNMaxY.test.ts +++ b/src/xy/__tests__/xyGetNMaxY.test.ts @@ -27,7 +27,7 @@ test('should return one peak', () => { test('should throw error', () => { const spectrum = { x: [1, 5], y: [1, 2, 3, 4] }; - expect(() => xyGetNMaxY(spectrum, 1)).toThrow( + expect(() => xyGetNMaxY(spectrum, 1)).toThrowError( 'the x and y arrays must have the same length', ); }); diff --git a/src/xy/__tests__/xyIntegral.test.ts b/src/xy/__tests__/xyIntegral.test.ts index 247c24b5..a8f461ca 100644 --- a/src/xy/__tests__/xyIntegral.test.ts +++ b/src/xy/__tests__/xyIntegral.test.ts @@ -7,7 +7,7 @@ test('zero element', () => { const x: number[] = []; const y: number[] = []; - expect(() => xyIntegral({ x, y })).toThrow( + expect(() => xyIntegral({ x, y })).toThrowError( 'data.x must have a length of at least 1', ); }); diff --git a/src/xy/__tests__/xyIntegration.test.ts b/src/xy/__tests__/xyIntegration.test.ts index 31ff792f..a76abfaa 100644 --- a/src/xy/__tests__/xyIntegration.test.ts +++ b/src/xy/__tests__/xyIntegration.test.ts @@ -6,7 +6,7 @@ test('zero element', () => { const x: number[] = []; const y: number[] = []; - expect(() => xyIntegration({ x, y })).toThrow( + expect(() => xyIntegration({ x, y })).toThrowError( 'data.x must have a length of at least 1', ); }); diff --git a/src/xy/__tests__/xyMassCenter.test.ts b/src/xy/__tests__/xyMassCenter.test.ts index acc4fc47..ac56d336 100644 --- a/src/xy/__tests__/xyMassCenter.test.ts +++ b/src/xy/__tests__/xyMassCenter.test.ts @@ -32,13 +32,13 @@ test('xyMassCenter', () => { expect( xyMassCenter({ x: [3, 2, 1], y: [1, 1, 1] }, { fromIndex: 1, toIndex: 1 }), ).toBe(2); - expect(() => xyMassCenter({ x: [], y: [] })).toThrow( + expect(() => xyMassCenter({ x: [], y: [] })).toThrowError( 'data.x must have a length of at least', ); - expect(() => xyMassCenter({ x: [1], y: [] })).toThrow( + expect(() => xyMassCenter({ x: [1], y: [] })).toThrowError( 'the x and y arrays must have the same', ); - expect(() => xyMassCenter({ x: [1, 2, 3], y: [0, 0, 0] })).toThrow( + expect(() => xyMassCenter({ x: [1, 2, 3], y: [0, 0, 0] })).toThrowError( 'Sum of Ys can not be zero.', ); }); diff --git a/src/xy/__tests__/xyRolling.test.ts b/src/xy/__tests__/xyRolling.test.ts index 5fd02ac6..95e07b89 100644 --- a/src/xy/__tests__/xyRolling.test.ts +++ b/src/xy/__tests__/xyRolling.test.ts @@ -8,7 +8,7 @@ test('xyRolling', () => { y: [10, 20, 30, 40, 50], }; - expect(() => xyRolling(points)).toThrow('fct must be a function'); + expect(() => xyRolling(points)).toThrowError('fct must be a function'); expect(xyRolling(points, () => 1, { window: 3 })).toStrictEqual({ x: [2, 3, 4], diff --git a/src/xy/__tests__/xyRollingCircleTransform.test.ts b/src/xy/__tests__/xyRollingCircleTransform.test.ts index 57559ed0..34f211b6 100644 --- a/src/xy/__tests__/xyRollingCircleTransform.test.ts +++ b/src/xy/__tests__/xyRollingCircleTransform.test.ts @@ -75,7 +75,7 @@ test('wrong position', () => { expect(() => { xyRollingCircleTransform(data, { position: 'middle' as 'top' }); - }).toThrow('Invalid position: middle'); + }).toThrowError('Invalid position: middle'); }); test('two peaks', () => { diff --git a/src/xyObject/__tests__/xyObjectCheck.test.ts b/src/xyObject/__tests__/xyObjectCheck.test.ts index 754a67ac..681e74f6 100644 --- a/src/xyObject/__tests__/xyObjectCheck.test.ts +++ b/src/xyObject/__tests__/xyObjectCheck.test.ts @@ -5,11 +5,11 @@ import { xyObjectCheck } from '../xyObjectCheck.ts'; test('xyObjectCheck', () => { expect(xyObjectCheck([{ x: 0, y: 1 }])).toBeUndefined(); // @ts-expect-error this is a testcase - expect(() => xyObjectCheck([{ x: 0, y: 'a' }])).toThrow( + expect(() => xyObjectCheck([{ x: 0, y: 'a' }])).toThrowError( 'points must be an array of {x,y} objects', ); // @ts-expect-error this is a testcase - expect(() => xyObjectCheck('a')).toThrow( + expect(() => xyObjectCheck('a')).toThrowError( 'points must be an array of {x,y} objects', ); expect( @@ -21,7 +21,7 @@ test('xyObjectCheck', () => { { minLength: 2 }, ), ).toBeUndefined(); - expect(() => xyObjectCheck([{ x: 0, y: 1 }], { minLength: 2 })).toThrow( + expect(() => xyObjectCheck([{ x: 0, y: 1 }], { minLength: 2 })).toThrowError( 'points must have a length of at least 2', ); }); diff --git a/src/xyObject/__tests__/xyObjectMinMaxValues.test.ts b/src/xyObject/__tests__/xyObjectMinMaxValues.test.ts index 99985f76..847f78d8 100644 --- a/src/xyObject/__tests__/xyObjectMinMaxValues.test.ts +++ b/src/xyObject/__tests__/xyObjectMinMaxValues.test.ts @@ -24,7 +24,7 @@ test('multiple elements', () => { }); test('throws error if array is empty', () => { - expect(() => xyObjectMinMaxValues([])).toThrow( + expect(() => xyObjectMinMaxValues([])).toThrowError( 'points must have a length of at least 1', ); }); From 16c464c9d931b0d53a48e30e461234e62060224a Mon Sep 17 00:00:00 2001 From: jobo322 Date: Thu, 4 Dec 2025 09:45:24 -0500 Subject: [PATCH 3/5] chore: fix prettier --- src/utils/calculateAdaptiveWeights.ts | 3 +-- src/x/xWhittakerSmoother.ts | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/src/utils/calculateAdaptiveWeights.ts b/src/utils/calculateAdaptiveWeights.ts index 4d3989a7..9486c2eb 100644 --- a/src/utils/calculateAdaptiveWeights.ts +++ b/src/utils/calculateAdaptiveWeights.ts @@ -16,8 +16,7 @@ export interface WeightsAndControlPoints { weights?: NumberArray; } -export interface CalculateAdaptiveWeightsOptions - extends WeightsAndControlPoints { +export interface CalculateAdaptiveWeightsOptions extends WeightsAndControlPoints { /** * Factor that determines how quickly the weights are updated in each iteration. * A value between 0 and 1, where higher values mean faster updates. diff --git a/src/x/xWhittakerSmoother.ts b/src/x/xWhittakerSmoother.ts index 136690d7..725cebb3 100644 --- a/src/x/xWhittakerSmoother.ts +++ b/src/x/xWhittakerSmoother.ts @@ -12,8 +12,7 @@ import { calculateAdaptiveWeights } from '../utils/index.ts'; import { xEnsureFloat64 } from './xEnsureFloat64.ts'; import { xMultiply } from './xMultiply.ts'; -export interface XWhittakerSmootherOptions - extends CalculateAdaptiveWeightsOptions { +export interface XWhittakerSmootherOptions extends CalculateAdaptiveWeightsOptions { /** * Factor of weights matrix in -> [I + lambda D'D]z = x * @default 100 From 9783da04bbf3890a8f14db5d98fed230be222118 Mon Sep 17 00:00:00 2001 From: jobo322 Date: Fri, 5 Dec 2025 10:52:49 -0500 Subject: [PATCH 4/5] chore: keep the input type in the result --- src/reim/__tests__/reimZeroFilling.test.ts | 22 ++++++++++++++++++ src/reim/reimZeroFilling.ts | 26 +++++++++++++++------- 2 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/reim/__tests__/reimZeroFilling.test.ts b/src/reim/__tests__/reimZeroFilling.test.ts index 4b4eea88..5208d79d 100644 --- a/src/reim/__tests__/reimZeroFilling.test.ts +++ b/src/reim/__tests__/reimZeroFilling.test.ts @@ -14,6 +14,28 @@ test('xreimZeroFilling over', () => { re: [0, 1, 2, 3, 0, 0], im: [4, 5, 6, 7, 0, 0], }); + + result.re.splice(0, 1, 1); + + expect(Array.from(result.re)).toStrictEqual([1, 1, 2, 3, 0, 0]); +}); + +test('xreimZeroFilling over with Float64', () => { + const re = new Float64Array([0, 1, 2, 3]); + const im = new Float64Array([4, 5, 6, 7]); + const result = reimZeroFilling({ re, im }, 6); + + const newRe = Array.from(result.re); + const newIm = Array.from(result.im); + + expect({ re: newRe, im: newIm }).toStrictEqual({ + re: [0, 1, 2, 3, 0, 0], + im: [4, 5, 6, 7, 0, 0], + }); + + result.re.set([1], 0); + + expect(Array.from(result.re)).toStrictEqual([1, 1, 2, 3, 0, 0]); }); test('xreimZeroFilling equal', () => { diff --git a/src/reim/reimZeroFilling.ts b/src/reim/reimZeroFilling.ts index a54a1cec..34f75337 100644 --- a/src/reim/reimZeroFilling.ts +++ b/src/reim/reimZeroFilling.ts @@ -1,6 +1,8 @@ import type { DoubleArray } from 'cheminfo-types'; import type { DataReIm } from '../types/index.ts'; +import type { DoubleArrayConstructor } from '../utils/createArray.ts'; +import { createDoubleArray } from '../utils/createArray.ts'; /** * This function make a zero filling to re and im part. @@ -13,7 +15,7 @@ import type { DataReIm } from '../types/index.ts'; export function reimZeroFilling( data: DataReIm, totalLength: number, -): DataReIm> { +): DataReIm { if (!Number.isInteger(totalLength) || totalLength < 0) { throw new RangeError('totalLength must be a non-negative integer'); } @@ -30,14 +32,22 @@ export function reimZeroFilling( }; } - const newRE = new Float64Array(totalLength); - const newIM = new Float64Array(totalLength); - - newRE.set(re); - newIM.set(im); + const newRE = createDoubleArray( + re.constructor as DoubleArrayConstructor, + totalLength, + ); + const newIM = createDoubleArray( + im.constructor as DoubleArrayConstructor, + totalLength, + ); + + for (let i = 0; i < re.length; i++) { + newRE[i] = re[i]; + newIM[i] = im[i]; + } return { - re: newRE, - im: newIM, + re: newRE as ArrayType, + im: newIM as ArrayType, }; } From af07ed9f84bcc3f619cf902ec9e975e8d34b9848 Mon Sep 17 00:00:00 2001 From: jobo322 Date: Mon, 8 Dec 2025 06:32:34 -0500 Subject: [PATCH 5/5] chore: test correctly the instance of results arrays --- src/reim/__tests__/reimZeroFilling.test.ts | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/reim/__tests__/reimZeroFilling.test.ts b/src/reim/__tests__/reimZeroFilling.test.ts index 5208d79d..8c53f447 100644 --- a/src/reim/__tests__/reimZeroFilling.test.ts +++ b/src/reim/__tests__/reimZeroFilling.test.ts @@ -15,9 +15,8 @@ test('xreimZeroFilling over', () => { im: [4, 5, 6, 7, 0, 0], }); - result.re.splice(0, 1, 1); - - expect(Array.from(result.re)).toStrictEqual([1, 1, 2, 3, 0, 0]); + expect(result.re).toBeInstanceOf(Array); + expect(result.im).toBeInstanceOf(Array); }); test('xreimZeroFilling over with Float64', () => { @@ -33,9 +32,8 @@ test('xreimZeroFilling over with Float64', () => { im: [4, 5, 6, 7, 0, 0], }); - result.re.set([1], 0); - - expect(Array.from(result.re)).toStrictEqual([1, 1, 2, 3, 0, 0]); + expect(result.re).toBeInstanceOf(Float64Array); + expect(result.im).toBeInstanceOf(Float64Array); }); test('xreimZeroFilling equal', () => {