|
| 1 | +import type { DataXY } from 'cheminfo-types'; |
| 2 | +import { toBeDeepCloseTo, toMatchCloseTo } from 'jest-matcher-deep-close-to'; |
| 3 | + |
| 4 | +import { gsd } from '../gsd'; |
| 5 | + |
| 6 | +expect.extend({ toBeDeepCloseTo, toMatchCloseTo }); |
| 7 | + |
| 8 | +// eslint-disable-next-line @typescript-eslint/no-var-requires |
| 9 | +const { generateSpectrum } = require('spectrum-generator'); |
| 10 | + |
| 11 | +describe('smooth:false option', () => { |
| 12 | + const peaks = [ |
| 13 | + { x: -0.5, y: 1, width: 0.05 }, |
| 14 | + { x: 0.5, y: 1, width: 0.05 }, |
| 15 | + ]; |
| 16 | + |
| 17 | + const data: DataXY = generateSpectrum(peaks, { |
| 18 | + generator: { |
| 19 | + from: -1, |
| 20 | + to: 1, |
| 21 | + nbPoints: 101, |
| 22 | + }, |
| 23 | + peaks: { |
| 24 | + factor: 6, |
| 25 | + }, |
| 26 | + noise: { |
| 27 | + percent: 5, |
| 28 | + }, |
| 29 | + }); |
| 30 | + |
| 31 | + it('positive maxima peaks but noiseLevel over the peaks', () => { |
| 32 | + let peakList = gsd(data, { noiseLevel: 1.2 }); |
| 33 | + expect(peakList).toStrictEqual([]); |
| 34 | + }); |
| 35 | + |
| 36 | + it('positive maxima peaks', () => { |
| 37 | + let peakList = gsd(data, { noiseLevel: 0.5 }); |
| 38 | + expect(peakList).toMatchCloseTo([ |
| 39 | + { x: -0.5, y: 1.131 }, |
| 40 | + { x: 0.5, y: 1.05 }, |
| 41 | + ]); |
| 42 | + }); |
| 43 | + |
| 44 | + it('negative maxima peaks', () => { |
| 45 | + let peakList = gsd( |
| 46 | + { x: data.x, y: data.y.map((value) => value - 2) }, |
| 47 | + { noiseLevel: -1.5 }, |
| 48 | + ); |
| 49 | + expect(peakList).toMatchCloseTo([ |
| 50 | + { x: -0.5, y: -0.868 }, |
| 51 | + { x: 0.5, y: -0.95 }, |
| 52 | + ]); |
| 53 | + }); |
| 54 | + |
| 55 | + it('Negative peaks', () => { |
| 56 | + // we check negative peaks |
| 57 | + let peakList = gsd( |
| 58 | + { x: data.x, y: data.y.map((value) => -value) }, |
| 59 | + { maxCriteria: false, noiseLevel: -0.5 }, |
| 60 | + ); |
| 61 | + expect(peakList).toMatchCloseTo([ |
| 62 | + { x: -0.5, y: -1.131 }, |
| 63 | + { x: 0.5, y: -1.05 }, |
| 64 | + ]); |
| 65 | + }); |
| 66 | + |
| 67 | + it('Negative peaks with noiseLevel too low', () => { |
| 68 | + // we check negative peaks |
| 69 | + let peakList = gsd( |
| 70 | + { x: data.x, y: data.y.map((value) => -value) }, |
| 71 | + { maxCriteria: false, noiseLevel: -1.2 }, |
| 72 | + ); |
| 73 | + expect(peakList).toStrictEqual([]); |
| 74 | + }); |
| 75 | + |
| 76 | + it('minima peaks', () => { |
| 77 | + // we check negative peaks |
| 78 | + let peakList = gsd( |
| 79 | + { x: data.x, y: data.y.map((value) => 1 - value) }, |
| 80 | + { maxCriteria: false, noiseLevel: 0.5 }, |
| 81 | + ); |
| 82 | + expect(peakList).toMatchCloseTo([ |
| 83 | + { x: -0.5, y: -0.131 }, |
| 84 | + { x: 0.5, y: -0.05 }, |
| 85 | + ]); |
| 86 | + }); |
| 87 | +}); |
0 commit comments