Skip to content

Commit

Permalink
test: add non x linear tests for xyReduce (#247)
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny authored Jun 15, 2024
1 parent 0801a40 commit 566bafd
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
23 changes: 23 additions & 0 deletions src/xy/__tests__/xyReduce.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,29 @@ test('xyCheck optimization', () => {
expect(result.y).toStrictEqual([0, 5, 10]);
});

test('xyCheck non-linear x', () => {
const xs = [];
const ys = [];
for (let i = 0; i < 11; i++) {
xs.push(i * 1.2 ** i);
ys.push(i);
}
const result = xyReduce({ x: xs, y: ys }, { nbPoints: 5 });
expect(result.y).toStrictEqual([0, 1, 8, 9, 10]);
});

test('xyCheck extreme non-linear x', () => {
const xs = [];
const ys = [];
for (let i = 0; i < 11; i++) {
xs.push(i * 2 ** i);
ys.push(i);
}
//console.log(xs, ys);
const result = xyReduce({ x: xs, y: ys }, { nbPoints: 5 });
expect(result.y).toStrictEqual([0, 1, 10]);
});

test('Part rounded far 2 with optimization', () => {
const result = xyReduce({ x, y }, { nbPoints: 5, optimize: true });

Expand Down
6 changes: 4 additions & 2 deletions src/xy/xyReduce.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export interface XYReduceOptions {
* */
nbPoints?: number;
/**
* If optimize we may have less than nbPoints at the end
* If optimize we may have less than nbPoints at the end. It should not have visible effects
* @default false
* */
optimize?: boolean;
Expand All @@ -42,7 +42,9 @@ export interface XYReduceOptions {

/**
* Reduce the number of points while keeping visually the same noise. Practical to
* display many spectra as SVG. If you want a similar looking spectrum you should still however generate 4x the nbPoints that is being displayed.
* display many spectra as SVG. If you want a similar looking spectrum you should still however
* generate at least 4x the nbPoints that is being displayed.
*
* SHOULD NOT BE USED FOR DATA PROCESSING !!!
* You should rather use ml-xy-equally-spaced to make further processing
*
Expand Down

0 comments on commit 566bafd

Please sign in to comment.