Skip to content

Commit 299933a

Browse files
committed
test: add power function test
1 parent 731d589 commit 299933a

File tree

1 file changed

+111
-0
lines changed

1 file changed

+111
-0
lines changed

src/__tests__/power.test.ts

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
describe('power', () => {
9+
const data: DataXY = {
10+
x: [
11+
0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, 0.35, 0.4, 0.45, 0.5, 0.55, 0.6, 0.65,
12+
0.7, 0.75, 0.8, 0.85, 0.9, 0.95, 1, 1.05, 1.1, 1.15, 1.2, 1.25, 1.3, 1.35,
13+
1.4, 1.45, 1.5, 1.55, 1.6, 1.65, 1.7, 1.75, 1.8, 1.85, 1.9, 1.95, 2, 2.05,
14+
2.1, 2.15, 2.2, 2.25, 2.3, 2.35, 2.4, 2.45, 2.5, 2.55, 2.6, 2.65, 2.7,
15+
2.75, 2.8, 2.85, 2.9, 2.95, 3, 3.05, 3.1, 3.15, 3.2, 3.25, 3.3, 3.35, 3.4,
16+
3.45, 3.5, 3.55, 3.6, 3.65, 3.7, 3.75, 3.8, 3.85, 3.9, 3.95, 4, 4.05, 4.1,
17+
4.15, 4.2, 4.25, 4.3, 4.35, 4.4, 4.45, 4.5, 4.55, 4.6, 4.65, 4.7, 4.75,
18+
4.8, 4.85, 4.9, 4.95, 5, 5.05, 5.1, 5.15, 5.2, 5.25, 5.3, 5.35, 5.4, 5.45,
19+
5.5, 5.55, 5.6, 5.65, 5.7, 5.75, 5.8, 5.85, 5.9, 5.95, 6, 6.05, 6.1, 6.15,
20+
6.2, 6.25, 6.3, 6.35, 6.4, 6.45, 6.5, 6.55, 6.6, 6.65, 6.7, 6.75, 6.8,
21+
6.85, 6.9, 6.95, 7, 7.05, 7.1, 7.15, 7.2, 7.25, 7.3, 7.35, 7.4, 7.45, 7.5,
22+
7.55, 7.6, 7.65, 7.7, 7.75, 7.8, 7.85, 7.9, 7.95, 8, 8.05, 8.1, 8.15, 8.2,
23+
8.25, 8.3, 8.35, 8.4, 8.45, 8.5, 8.55, 8.6, 8.65, 8.7, 8.75, 8.8, 8.85,
24+
8.9, 8.95, 9, 9.05, 9.1, 9.15, 9.2, 9.25, 9.3, 9.35, 9.4, 9.45, 9.5, 9.55,
25+
9.6, 9.65, 9.7, 9.75, 9.8, 9.85, 9.9, 9.95, 10,
26+
],
27+
y: [
28+
0, 1, 4, 9, 16, 25, 36, 49, 64, 81, 100, 121, 144, 169, 196, 225, 256,
29+
289, 324, 361, 400, 441, 484, 529, 576, 625, 676, 729, 784, 841, 900, 961,
30+
1024, 1089, 1156, 1225, 1296, 1369, 1444, 1521, 1600, 1681, 1764, 1849,
31+
1936, 2025, 2116, 2209, 2304, 2401, 2500, 2601, 2704, 2809, 2916, 3025,
32+
3136, 3249, 3364, 3481, 3600, 3721, 3844, 3969, 4096, 4225, 4356, 4489,
33+
4624, 4761, 4900, 5041, 5184, 5329, 5476, 5625, 5776, 5929, 6084, 6241,
34+
6400, 6561, 6724, 6889, 7056, 7225, 7396, 7569, 7744, 7921, 8100, 8281,
35+
8464, 8649, 8836, 9025, 9216, 9409, 9604, 9801, 10000, 9801, 9604, 9409,
36+
9216, 9025, 8836, 8649, 8464, 8281, 8100, 7921, 7744, 7569, 7396, 7225,
37+
7056, 6889, 6724, 6561, 6400, 6241, 6084, 5929, 5776, 5625, 5476, 5329,
38+
5184, 5041, 4900, 4761, 4624, 4489, 4356, 4225, 4096, 3969, 3844, 3721,
39+
3600, 3481, 3364, 3249, 3136, 3025, 2916, 2809, 2704, 2601, 2500, 2401,
40+
2304, 2209, 2116, 2025, 1936, 1849, 1764, 1681, 1600, 1521, 1444, 1369,
41+
1296, 1225, 1156, 1089, 1024, 961, 900, 841, 784, 729, 676, 625, 576, 529,
42+
484, 441, 400, 361, 324, 289, 256, 225, 196, 169, 144, 121, 100, 81, 64,
43+
49, 36, 25, 16, 9, 4, 1, 0,
44+
],
45+
};
46+
47+
// when smoothY we should take care that the peak is still as the same position but the height will be reduced
48+
// we have here a low resolution spectrum so the impact is big
49+
50+
it('default options', () => {
51+
let peakList = gsd(data);
52+
let expected = [
53+
{
54+
x: 5,
55+
y: 10000,
56+
width: 0.3,
57+
index: 100,
58+
ddY: -33832.03463203485,
59+
inflectionPoints: {
60+
from: { x: 4.85, index: 97 },
61+
to: { x: 5.15, index: 103 },
62+
},
63+
},
64+
];
65+
expect(peakList).toBeDeepCloseTo(expected);
66+
});
67+
it('custom options', () => {
68+
let peakList = gsd(data, {
69+
smoothY: false,
70+
sgOptions: { windowSize: 7, polynomial: 3 },
71+
});
72+
// not sure this is what we would like but this is the current result.
73+
// This shape is anyway quite strange
74+
const expected = [
75+
{
76+
x: 4.45,
77+
y: 7921,
78+
width: 0.05,
79+
index: 89,
80+
ddY: 800,
81+
inflectionPoints: {
82+
from: { x: 4.4, index: 88 },
83+
to: { x: 4.45, index: 89 },
84+
},
85+
},
86+
{
87+
x: 5,
88+
y: 10000,
89+
width: 0.2,
90+
index: 100,
91+
ddY: -44914.28571428623,
92+
inflectionPoints: {
93+
from: { x: 4.9, index: 98 },
94+
to: { x: 5.1, index: 102 },
95+
},
96+
},
97+
{
98+
x: 5.55,
99+
y: 7921,
100+
width: 0.05,
101+
index: 111,
102+
ddY: 800,
103+
inflectionPoints: {
104+
from: { x: 5.55, index: 111 },
105+
to: { x: 5.6, index: 112 },
106+
},
107+
},
108+
];
109+
expect(peakList).toBeDeepCloseTo(expected);
110+
});
111+
});

0 commit comments

Comments
 (0)