Skip to content

Commit

Permalink
chore: fix prettier
Browse files Browse the repository at this point in the history
  • Loading branch information
lpatiny committed May 16, 2024
1 parent db9724e commit d449f49
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 22 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"prepack": "npm run compile",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test": "npm run test-coverage && npm run eslint",
"test": "npm run test-coverage && npm run eslint && npm run prettier",
"test-only": "jest",
"test-coverage": "jest --coverage"
},
Expand All @@ -39,6 +39,7 @@
"eslint": "^8.57.0",
"eslint-config-cheminfo": "^9.2.0",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"rollup": "^4.17.2"
},
"dependencies": {
Expand Down
23 changes: 7 additions & 16 deletions src/__tests__/index.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,14 @@ describe('Power regression', () => {
it('basic test', () => {
const x = [17.6, 26, 31.9, 38.9, 45.8, 51.2, 58.1, 64.7, 66.7, 80.8, 82.9];
const y = [
159.9,
206.9,
236.8,
269.9,
300.6,
323.6,
351.7,
377.6,
384.1,
437.2,
444.7
159.9, 206.9, 236.8, 269.9, 300.6, 323.6, 351.7, 377.6, 384.1, 437.2,
444.7,
];
const result = new PowerRegression(x, y);

const expected = {
A: 24.12989312,
B: 0.65949782
B: 0.65949782,
};
expect(result.A).toBeCloseTo(expected.A, 10e-4);
expect(result.B).toBeCloseTo(expected.B, 10e-4);
Expand All @@ -43,7 +34,7 @@ describe('Power regression', () => {
const regression = PowerRegression.load({
name: 'powerRegression',
A: 1,
B: -1
B: -1,
});

expect(regression.predict(4)).toStrictEqual(0.25);
Expand All @@ -52,19 +43,19 @@ describe('Power regression', () => {
expect(model).toStrictEqual({
name: 'powerRegression',
A: 1,
B: -1
B: -1,
});
});

it('test latex formatting of big / small numbers', () => {
const regression = PowerRegression.load({
name: 'powerRegression',
A: 1000000000,
B: -0.000000001
B: -0.000000001,
});

expect(regression.toLaTeX(4)).toStrictEqual(
'f(x) = \\frac{1.000e^{+9}}{x^{1.000e^{-9}}}'
'f(x) = \\frac{1.000e^{+9}}{x^{1.000e^{-9}}}',
);
});
});
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import {
BaseRegression,
checkArrayLength,
maybeToPrecision
maybeToPrecision,
} from 'ml-regression-base';
import { SimpleLinearRegression } from 'ml-regression-simple-linear';

Expand All @@ -26,14 +26,14 @@ export class PowerRegression extends BaseRegression {
return {
name: 'powerRegression',
A: this.A,
B: this.B
B: this.B,
};
}

toString(precision) {
return `f(x) = ${maybeToPrecision(
this.A,
precision
precision,
)} * x^${maybeToPrecision(this.B, precision)}`;
}

Expand All @@ -42,12 +42,12 @@ export class PowerRegression extends BaseRegression {
if (this.B >= 0) {
latex = `f(x) = ${maybeToPrecision(
this.A,
precision
precision,
)}x^{${maybeToPrecision(this.B, precision)}}`;
} else {
latex = `f(x) = \\frac{${maybeToPrecision(
this.A,
precision
precision,
)}}{x^{${maybeToPrecision(-this.B, precision)}}}`;
}
latex = latex.replace(/e([+-]?[0-9]+)/g, 'e^{$1}');

Check warning on line 53 in src/index.js

View workflow job for this annotation

GitHub Actions / nodejs / lint-eslint

Capture group '([+-]?[0-9]+)' should be converted to a named or non-capturing group
Expand Down

0 comments on commit d449f49

Please sign in to comment.