|
| 1 | +import { toMatchCloseTo } from 'jest-matcher-deep-close-to'; |
| 2 | +import { getShape1D } from 'ml-peak-shape-generator'; |
| 3 | + |
| 4 | +import { addMissingShape } from '../addMissingShape'; |
| 5 | + |
| 6 | +expect.extend({ toMatchCloseTo }); |
| 7 | + |
| 8 | +describe('addMissingShape', () => { |
| 9 | + it('gaussian shape', () => { |
| 10 | + let result = addMissingShape([ |
| 11 | + { |
| 12 | + x: 5, |
| 13 | + y: 10, |
| 14 | + width: 5, |
| 15 | + index: 1, |
| 16 | + }, |
| 17 | + { |
| 18 | + x: 10, |
| 19 | + y: 10, |
| 20 | + width: 10, |
| 21 | + index: 2, |
| 22 | + }, |
| 23 | + { |
| 24 | + x: 30, |
| 25 | + y: 10, |
| 26 | + width: 15, |
| 27 | + index: 3, |
| 28 | + shape: { kind: 'lorentzian', fwhm: 5.8870501125773735 * 3 }, |
| 29 | + }, |
| 30 | + ]); |
| 31 | + expect(result).toMatchCloseTo([ |
| 32 | + { |
| 33 | + x: 5, |
| 34 | + y: 10, |
| 35 | + width: 5, |
| 36 | + index: 1, |
| 37 | + shape: { kind: 'gaussian', fwhm: 5.8870501125773735 }, |
| 38 | + }, |
| 39 | + { |
| 40 | + x: 10, |
| 41 | + y: 10, |
| 42 | + width: 10, |
| 43 | + index: 2, |
| 44 | + shape: { kind: 'gaussian', fwhm: 5.8870501125773735 * 2 }, |
| 45 | + }, |
| 46 | + { |
| 47 | + x: 30, |
| 48 | + y: 10, |
| 49 | + width: 15, |
| 50 | + index: 3, |
| 51 | + shape: { kind: 'lorentzian', fwhm: 5.8870501125773735 * 3 }, |
| 52 | + }, |
| 53 | + ]); |
| 54 | + }); |
| 55 | + it('lorentzian shape', () => { |
| 56 | + let result = addMissingShape( |
| 57 | + [ |
| 58 | + { |
| 59 | + x: 5, |
| 60 | + y: 10, |
| 61 | + width: 5, |
| 62 | + index: 1, |
| 63 | + inflectionPoints: { |
| 64 | + from: { x: 0, index: 0 }, |
| 65 | + to: { x: 0, index: 0 }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + { |
| 69 | + x: 10, |
| 70 | + y: 10, |
| 71 | + width: 10, |
| 72 | + index: 2, |
| 73 | + inflectionPoints: { |
| 74 | + from: { x: 0, index: 0 }, |
| 75 | + to: { x: 0, index: 0 }, |
| 76 | + }, |
| 77 | + shape: { kind: 'pseudoVoigt', fwhm: 8.660254037844386 * 2, mu: 0.5 }, |
| 78 | + }, |
| 79 | + { |
| 80 | + x: 30, |
| 81 | + y: 10, |
| 82 | + width: 15, |
| 83 | + index: 3, |
| 84 | + inflectionPoints: { |
| 85 | + from: { x: 0, index: 0 }, |
| 86 | + to: { x: 0, index: 0 }, |
| 87 | + }, |
| 88 | + }, |
| 89 | + ], |
| 90 | + { shape: { kind: 'lorentzian' } }, |
| 91 | + ); |
| 92 | + expect(result).toMatchCloseTo([ |
| 93 | + { |
| 94 | + x: 5, |
| 95 | + y: 10, |
| 96 | + width: 5, |
| 97 | + index: 1, |
| 98 | + shape: { kind: 'lorentzian', fwhm: 8.660254037844386 }, |
| 99 | + inflectionPoints: { from: { x: 0, index: 0 }, to: { x: 0, index: 0 } }, |
| 100 | + }, |
| 101 | + { |
| 102 | + x: 10, |
| 103 | + y: 10, |
| 104 | + width: 10, |
| 105 | + index: 2, |
| 106 | + shape: { kind: 'pseudoVoigt', fwhm: 8.660254037844386 * 2, mu: 0.5 }, |
| 107 | + inflectionPoints: { from: { x: 0, index: 0 }, to: { x: 0, index: 0 } }, |
| 108 | + }, |
| 109 | + { |
| 110 | + x: 30, |
| 111 | + y: 10, |
| 112 | + width: 15, |
| 113 | + index: 3, |
| 114 | + shape: { kind: 'lorentzian', fwhm: 8.660254037844386 * 3 }, |
| 115 | + inflectionPoints: { from: { x: 0, index: 0 }, to: { x: 0, index: 0 } }, |
| 116 | + }, |
| 117 | + ]); |
| 118 | + }); |
| 119 | + it('pseudovoigt shape', () => { |
| 120 | + let result = addMissingShape( |
| 121 | + [ |
| 122 | + { |
| 123 | + x: 5, |
| 124 | + y: 10, |
| 125 | + width: 5, |
| 126 | + index: 1, |
| 127 | + inflectionPoints: { |
| 128 | + from: { x: 0, index: 0 }, |
| 129 | + to: { x: 0, index: 0 }, |
| 130 | + }, |
| 131 | + }, |
| 132 | + { |
| 133 | + x: 5, |
| 134 | + y: 10, |
| 135 | + width: 5, |
| 136 | + index: 1, |
| 137 | + inflectionPoints: { |
| 138 | + from: { x: 0, index: 0 }, |
| 139 | + to: { x: 0, index: 0 }, |
| 140 | + }, |
| 141 | + shape: { kind: 'gaussian' }, |
| 142 | + }, |
| 143 | + ], |
| 144 | + { shape: { kind: 'pseudoVoigt', mu: 0.5 } }, |
| 145 | + ); |
| 146 | + expect(result).toMatchCloseTo([ |
| 147 | + { |
| 148 | + x: 5, |
| 149 | + y: 10, |
| 150 | + width: 5, |
| 151 | + index: 1, |
| 152 | + shape: { kind: 'pseudoVoigt', fwhm: 5.443525056288687, mu: 0.5 }, |
| 153 | + inflectionPoints: { from: { x: 0, index: 0 }, to: { x: 0, index: 0 } }, |
| 154 | + }, |
| 155 | + { |
| 156 | + x: 5, |
| 157 | + y: 10, |
| 158 | + width: 5, |
| 159 | + index: 1, |
| 160 | + inflectionPoints: { |
| 161 | + from: { x: 0, index: 0 }, |
| 162 | + to: { x: 0, index: 0 }, |
| 163 | + }, |
| 164 | + shape: { |
| 165 | + kind: 'gaussian', |
| 166 | + fwhm: getShape1D({ kind: 'gaussian' }).widthToFWHM(5), |
| 167 | + }, |
| 168 | + }, |
| 169 | + ]); |
| 170 | + }); |
| 171 | +}); |
0 commit comments