Skip to content

Commit

Permalink
test: try to add test to check if we didn't messup with default export
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed Oct 21, 2024
1 parent 681ce9f commit 53024d9
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 6 deletions.
6 changes: 2 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"scripts": {
"build": "cheminfo-build --root ML",
"compile": "rollup -c",
"dupe": "find-duplicate-dependencies",
"eslint": "eslint src --cache",
"eslint-fix": "npm run eslint -- --fix",
"prepack": "npm run compile",
Expand Down Expand Up @@ -86,13 +85,13 @@
"ml-pca": "^4.1.1",
"ml-performance": "^0.2.0",
"ml-pls": "^4.3.2",
"ml-random": "^1.0.1",
"ml-random": "^2.0.0",
"ml-random-forest": "^2.1.0",
"ml-regression": "^6.2.0",
"ml-savitzky-golay": "^5.0.0",
"ml-som": "^0.0.6",
"ml-sparse-matrix": "^2.1.0",
"ml-xsadd": "^2.0.0",
"ml-xsadd": "^3.0.1",
"num-sort": "^3.0.0"
},
"devDependencies": {
Expand All @@ -102,7 +101,6 @@
"eslint": "^9.12.0",
"eslint-config-cheminfo": "^12.0.1",
"esm": "^3.2.25",
"find-duplicate-dependencies": "^3.0.0",
"prettier": "^3.3.3",
"rollup": "^4.24.0",
"vitest": "^2.1.3"
Expand Down
30 changes: 30 additions & 0 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,37 @@ import { it, describe, expect } from 'vitest';
import * as ML from '..';

describe('Check all properties are defined', () => {
const objectsAndNbKeys = {
Distance: 42,
Similarity: 11,
Array: 11,
ArrayXY: 10,
BitArray: 12,
KMeans: 2,
HClust: 2,
NaiveBayes: 2,
CrossValidation: 6,
FCNNLS: 2,
MatrixLib: 36,
GSD: 7,
};

it.each(Object.keys(ML))('Check %s', (key) => {
// if a function it should key should start with lowercase
// if a class it should key should start with uppercase
expect(ML[key]).toBeDefined();

if (objectsAndNbKeys[key]) {
expect(typeof ML[key]).toBe('object');
expect(Object.keys(ML[key]).length).toBe(objectsAndNbKeys[key]);
} else if (key[0] === key[0].toUpperCase()) {
// should be a class
expect(typeof ML[key]).toBe('function');
expect(typeof ML[key].prototype).toBe('object');
expect(ML[key].prototype?.constructor).toBe(ML[key]);
} else {
// should be function
expect(typeof ML[key]).toBe('function');
}
});
});
4 changes: 2 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export { SparseMatrix } from 'ml-sparse-matrix';
export { default as Kernel } from 'ml-kernel';
export { distance as Distance, similarity as Similarity } from 'ml-distance';
export { default as distanceMatrix } from 'ml-distance-matrix';
export { default as XSadd } from 'ml-xsadd';
export { XSadd } from 'ml-xsadd';
export { nGMCA } from 'ml-ngmca';

// Statistics
Expand All @@ -69,7 +69,7 @@ export { default as BitArray } from 'ml-bit-array';
export { default as HashTable } from 'ml-hash-table';
export { default as padArray } from 'ml-pad-array';
export { default as binarySearch } from 'binary-search';
export { default as Random } from 'ml-random';
export { Random } from 'ml-random';

import min from 'ml-array-min';
import max from 'ml-array-max';
Expand Down

0 comments on commit 53024d9

Please sign in to comment.