Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
name: Deploy documentation.js on GitHub pages
name: Deploy TypeDoc on GitHub pages

on:
workflow_dispatch:
release:
types: [published]

env:
ENTRY_FILE: 'src/index.js'
NODE_VERSION: 22.x
ENTRY_FILE: 'src/index.ts'

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: npm install
- name: Build documentation
uses: zakodium/documentationjs-action@v1
uses: zakodium/typedoc-action@v2
with:
entry: ${{ env.ENTRY_FILE }}
- name: Deploy to GitHub pages
Expand Down
2 changes: 1 addition & 1 deletion src/__tests__/curve.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ function sinFunction([a, b]: number[]) {

test('linear regression', () => {
function line([a, b]: number[]) {
return (x) => a * x + b;
return (x: number) => a * x + b;
}

const x = [0, 1, 2, 3, 4, 5, 6];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { describe, expect, it } from 'vitest';

import errorCalculation from '../errorCalculation.js';
import errorCalculation from '../error_calculation.js';

describe('parameterError', () => {
describe('Linear functions', () => {
Expand All @@ -11,7 +11,7 @@ describe('parameterError', () => {
/** @type [number, number] */
const sampleParameters = [1, 1];
const n = 10;
const w = new Float64Array(n).fill(1);
const w = new Array(n).fill(1);
const xs = new Array(n).fill(0).map((zero, i) => i);
const data = {
x: xs,
Expand Down Expand Up @@ -46,7 +46,7 @@ describe('parameterError', () => {
const n = 10;
const x = new Float64Array(n);
const y = new Float64Array(n);
const w = new Float64Array(n);
const w = new Array(n);
const fct = linearFunction(sampleParameters);
for (let i = 0; i < n; i++) {
x[i] = i;
Expand Down
55 changes: 37 additions & 18 deletions src/__tests__/exceptions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,34 @@ import { describe, expect, it } from 'vitest';

import { levenbergMarquardt } from '../index.js';

function sinFunction([a, b]) {
return (t) => a * Math.sin(b * t);
function sinFunction([a, b]: number[]) {
return (t: number) => a * Math.sin(b * t);
}

describe('Handling of invalid arguments', () => {
describe('options', () => {
it('Should throw an error when bad options are provided (negative damping)', () => {
// @ts-expect-error check if it throws an error
expect(() => levenbergMarquardt({}, () => 1, { damping: -1 })).toThrow(
'The damping option must be a positive number',
);
expect(() =>
levenbergMarquardt({ x: [], y: [] }, () => () => 1, {
damping: -1,
initialValues: [],
}),
).toThrow('The damping option must be a positive number');
});

it('Should throw an error when initialValues is not an array', () => {
const expectedErrorMessage =
'The initialValues option is mandatory and must be an array';
const inputData = { x: [1, 2], y: [1, 2] };
expect(() =>
// @ts-expect-error check if it throws an error
levenbergMarquardt(inputData, sinFunction, {
damping: 0.1,
}),
} as never),
).toThrow(expectedErrorMessage);
expect(() =>
levenbergMarquardt(inputData, sinFunction, {
damping: 0.1,
// @ts-expect-error check if it throws an error
initialValues: 2,
initialValues: 2 as never,
}),
).toThrow(expectedErrorMessage);
});
Expand All @@ -44,6 +44,28 @@ describe('Handling of invalid arguments', () => {
}),
).toThrow('minValues and maxValues must be the same size');
});

it('Should throw an error when weights is not a number or an array', () => {
expect(() => {
levenbergMarquardt({ x: [0, 0, 0], y: [0, 0, 0] }, sinFunction, {
initialValues: [0, 0, 0],
weights: { length: 3 },
});
}).toThrow(
'weights should be a number or array with length equal to the number of data points',
);
});

it('Should throw an error when gradientDifference is not a number or an array', () => {
expect(() => {
levenbergMarquardt({ x: [0, 0, 0], y: [0, 0, 0] }, sinFunction, {
initialValues: [0, 0, 0],
gradientDifference: { length: 3 },
});
}).toThrow(
'gradientDifference should be a number or array with length equal to the number of parameters',
);
});
});

describe('data', () => {
Expand All @@ -53,16 +75,14 @@ describe('Handling of invalid arguments', () => {
};

it('Should throw an error when data is an array (should be object)', () => {
// @ts-expect-error check if it throws an error
expect(() => levenbergMarquardt([1, 2], sinFunction, options)).toThrow(
'The data parameter must have x and y elements',
);
expect(() =>
levenbergMarquardt([1, 2] as never, sinFunction, options),
).toThrow('The data parameter must have x and y elements');
});

it('Should throw an error when data.{x,y} are numbers (should be arrays)', () => {
expect(() =>
// @ts-expect-error check if it throws an error
levenbergMarquardt({ x: 1, y: 2 }, sinFunction, options),
levenbergMarquardt({ x: 1, y: 2 } as never, sinFunction, options),
).toThrow(
'The data parameter elements must be an array with more than 2 points',
);
Expand Down Expand Up @@ -126,13 +146,12 @@ describe('Handling of ill-behaved functions', () => {

it('Should throw because is not a number', () => {
const options = {
timeout: 'a',
timeout: 'a' as never,
damping: 0.00001,
maxIterations: 200,
initialValues: [0, 100, 1, 0.1],
};

// @ts-expect-error check if it throws an error
expect(() => levenbergMarquardt(data, fourParamEq, options)).toThrow(
`timeout should be a number`,
);
Expand Down
113 changes: 0 additions & 113 deletions src/checkOptions.js

This file was deleted.

Loading