-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix!: improve types in xreim functions
- Loading branch information
Showing
7 changed files
with
75 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,10 @@ | ||
import { DoubleArray } from 'cheminfo-types'; | ||
|
||
export interface DataXReIm { | ||
export interface DataXReIm<ArrayType extends DoubleArray = DoubleArray> { | ||
/** Array of x values */ | ||
x: DoubleArray; | ||
x: ArrayType; | ||
/** Array of re values */ | ||
re: DoubleArray; | ||
re: ArrayType; | ||
/** Array of im values */ | ||
im: DoubleArray; | ||
im: ArrayType; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,29 +1,27 @@ | ||
import { xreimSortX } from '../../index'; | ||
import { xreimSortX } from '../xreimSortX'; | ||
|
||
describe('xreimSortX', () => { | ||
it('test xreimSortX do nothing', () => { | ||
const x = [0, 1, 2, 3]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimSortX({ x, re, im }); | ||
test('test xreimSortX do nothing', () => { | ||
const x = [0, 1, 2, 3]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimSortX({ x, re, im }); | ||
|
||
expect(result).toStrictEqual({ | ||
x: [0, 1, 2, 3], | ||
re: [0, 1, 2, 3], | ||
im: [4, 5, 6, 7], | ||
}); | ||
expect(result).toStrictEqual({ | ||
x: [0, 1, 2, 3], | ||
re: [0, 1, 2, 3], | ||
im: [4, 5, 6, 7], | ||
}); | ||
}); | ||
|
||
it('test xreimSortX reverse', () => { | ||
const x = [3, 2, 1, 0]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimSortX({ x, re, im }); | ||
test('test xreimSortX reverse', () => { | ||
const x = [3, 2, 1, 0]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimSortX({ x, re, im }); | ||
|
||
expect(result).toStrictEqual({ | ||
x: [0, 1, 2, 3], | ||
re: [3, 2, 1, 0], | ||
im: [7, 6, 5, 4], | ||
}); | ||
expect(result).toStrictEqual({ | ||
x: [0, 1, 2, 3], | ||
re: [3, 2, 1, 0], | ||
im: [7, 6, 5, 4], | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,50 @@ | ||
import { xreimZeroFilling } from '../../index'; | ||
import { xreimZeroFilling } from '../xreimZeroFilling'; | ||
|
||
describe('xreimZeroFilling', () => { | ||
it('test xreimZeroFilling over', () => { | ||
const x = [0, 0.1, 0.2, 0.3]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimZeroFilling({ x, re, im }, 6); | ||
const newX = Array.from(result.x).map( | ||
(value) => Math.round(value * 10) / 10, | ||
); | ||
test('test xreimZeroFilling over', () => { | ||
const x = [0, 0.1, 0.2, 0.3]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimZeroFilling({ x, re, im }, 6); | ||
const newX = Array.from(result.x).map((value) => Math.round(value * 10) / 10); | ||
|
||
const newRe = Array.from(result.re); | ||
const newIm = Array.from(result.im); | ||
const newRe = Array.from(result.re); | ||
const newIm = Array.from(result.im); | ||
|
||
expect({ x: newX, re: newRe, im: newIm }).toStrictEqual({ | ||
x: [0, 0.1, 0.2, 0.3, 0.4, 0.5], | ||
re: [0, 1, 2, 3, 0, 0], | ||
im: [4, 5, 6, 7, 0, 0], | ||
}); | ||
expect({ x: newX, re: newRe, im: newIm }).toStrictEqual({ | ||
x: [0, 0.1, 0.2, 0.3, 0.4, 0.5], | ||
re: [0, 1, 2, 3, 0, 0], | ||
im: [4, 5, 6, 7, 0, 0], | ||
}); | ||
}); | ||
|
||
it('test xreimZeroFilling equal', () => { | ||
const x = [0, 0.1, 0.2, 0.3]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimZeroFilling({ x, re, im }, 4); | ||
const newX = Array.from(result.x); | ||
const newRe = Array.from(result.re); | ||
const newIm = Array.from(result.im); | ||
test('test xreimZeroFilling equal', () => { | ||
const x = [0, 0.1, 0.2, 0.3]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimZeroFilling({ x, re, im }, 4); | ||
const newX = Array.from(result.x); | ||
const newRe = Array.from(result.re); | ||
const newIm = Array.from(result.im); | ||
|
||
expect({ x: newX, re: newRe, im: newIm }).toStrictEqual({ | ||
x: [0, 0.1, 0.2, 0.3], | ||
re: [0, 1, 2, 3], | ||
im: [4, 5, 6, 7], | ||
}); | ||
expect({ x: newX, re: newRe, im: newIm }).toStrictEqual({ | ||
x: [0, 0.1, 0.2, 0.3], | ||
re: [0, 1, 2, 3], | ||
im: [4, 5, 6, 7], | ||
}); | ||
}); | ||
|
||
it('test xreimZeroFilling under', () => { | ||
const x = [0, 0.1, 0.2, 0.3]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimZeroFilling({ x, re, im }, 2); | ||
const newX = Array.from(result.x); | ||
const newRe = Array.from(result.re); | ||
const newIm = Array.from(result.im); | ||
test('test xreimZeroFilling under', () => { | ||
const x = [0, 0.1, 0.2, 0.3]; | ||
const re = [0, 1, 2, 3]; | ||
const im = [4, 5, 6, 7]; | ||
const result = xreimZeroFilling({ x, re, im }, 2); | ||
const newX = Array.from(result.x); | ||
const newRe = Array.from(result.re); | ||
const newIm = Array.from(result.im); | ||
|
||
expect({ x: newX, re: newRe, im: newIm }).toStrictEqual({ | ||
x: [0, 0.1], | ||
re: [0, 1], | ||
im: [4, 5], | ||
}); | ||
expect({ x: newX, re: newRe, im: newIm }).toStrictEqual({ | ||
x: [0, 0.1], | ||
re: [0, 1], | ||
im: [4, 5], | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './xreimZeroFilling'; | ||
export * from './xreimSortX'; | ||
export * from './xreimZeroFilling'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import { DataXReIm } from '../types'; | ||
|
||
/** | ||
* This function make a zero filling to re and im part. | ||
* | ||
|