From 443887ffbe9f9bd2b923bc2ff810405c19bf2b33 Mon Sep 17 00:00:00 2001 From: Jose Alejandro Bolanos Arroyave Date: Tue, 30 Jul 2024 09:42:45 -0500 Subject: [PATCH] fix: remove zone if no points in xyEquallySpaced * chore: add failing test case * --------- Co-authored-by: Luc Patiny --- package.json | 10 +++++----- src/xy/__tests__/xyEquallySpaced.test.ts | 21 +++++++++++++++++++++ src/xy/xyEquallySpaced.ts | 3 +-- 3 files changed, 27 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index cc362791..1922fea6 100644 --- a/package.json +++ b/package.json @@ -88,25 +88,25 @@ }, "homepage": "https://github.com/mljs/spectra-processing#readme", "devDependencies": { - "@vitest/coverage-v8": "^1.5.3", + "@vitest/coverage-v8": "^2.0.4", "cheminfo-build": "^1.2.0", "eslint": "^8.57.0", "eslint-config-cheminfo-typescript": "^12.4.0", "jest-matcher-deep-close-to": "^3.0.2", "jscpd": "^3.5.10", "ml-spectra-fitting": "^4.2.3", - "prettier": "^3.2.5", + "prettier": "^3.3.3", "rimraf": "^5.0.5", "spectrum-generator": "^8.0.11", - "typescript": "^5.4.5", - "vitest": "^1.5.3" + "typescript": "^5.5.4", + "vitest": "^2.0.4" }, "dependencies": { "binary-search": "^1.3.6", "cheminfo-types": "^1.7.3", "fft.js": "^4.0.4", "is-any-array": "^2.0.1", - "ml-matrix": "^6.11.0", + "ml-matrix": "^6.11.1", "ml-xsadd": "^2.0.0", "spline-interpolator": "^1.0.0" } diff --git a/src/xy/__tests__/xyEquallySpaced.test.ts b/src/xy/__tests__/xyEquallySpaced.test.ts index 16dbddfc..610a29c3 100644 --- a/src/xy/__tests__/xyEquallySpaced.test.ts +++ b/src/xy/__tests__/xyEquallySpaced.test.ts @@ -3,8 +3,29 @@ import { join } from 'path'; import { expect, test } from 'vitest'; +import { xSequentialFillFromTo } from '../../x/xSequentialFillFromTo'; import { xyEquallySpaced } from '../xyEquallySpaced'; +test('one zone with zero point', () => { + const size = 256; + const x = xSequentialFillFromTo({ from: 0, to: 100, size }); + const y = x.slice(); + + const from = x[size / 2]; + const to = x[size / 2 + 1]; + const ans = xyEquallySpaced( + { x, y }, + { + numberOfPoints: 64, + zones: [ + { from, to }, + { from: 0, to: 50 }, + ], + }, + ); + expect(ans.x).toHaveLength(64); +}); + test('testing 1 points', () => { const x = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; const y = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]; diff --git a/src/xy/xyEquallySpaced.ts b/src/xy/xyEquallySpaced.ts index 865c7164..6da4ace9 100644 --- a/src/xy/xyEquallySpaced.ts +++ b/src/xy/xyEquallySpaced.ts @@ -84,11 +84,10 @@ export function xyEquallySpaced( } const normalizedZones = zonesNormalize(zones, { from, to, exclusions }); - const zonesWithPointsRes = zonesWithPoints(normalizedZones, numberOfPoints, { from, to, - }); + }).filter((zone) => zone.numberOfPoints); let xResult: number[] = []; let yResult: number[] = [];