Skip to content

Commit c0bcdfd

Browse files
committed
test: expect failure for Math.sin test on macOS
1 parent 699360e commit c0bcdfd

File tree

1 file changed

+40
-30
lines changed

1 file changed

+40
-30
lines changed

src/__tests__/curve.test.ts

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import * as os from 'node:os';
2+
13
import { describe, expect, it, test } from 'vitest';
24

35
import { levenbergMarquardt } from '../index.js';
@@ -177,37 +179,45 @@ describe('curve', () => {
177179
});
178180
});
179181

180-
it('should return solution with lowest error', () => {
181-
const data = {
182-
x: [
183-
0, 0.6283185307179586, 1.2566370614359172, 1.8849555921538759,
184-
2.5132741228718345, 3.141592653589793, 3.7699111843077517,
185-
4.39822971502571, 5.026548245743669, 5.654866776461628,
186-
],
187-
y: [
188-
0, 1.902113032590307, 1.1755705045849465, -1.175570504584946,
189-
-1.9021130325903073, -4.898587196589413e-16, 1.902113032590307,
190-
1.1755705045849467, -1.1755705045849456, -1.9021130325903075,
191-
],
192-
};
193-
const options = {
194-
damping: 1.5,
195-
initialValues: [0.594398586701882, 0.3506424963635226],
196-
gradientDifference: 1e-2,
197-
maxIterations: 100,
198-
errorTolerance: 1e-2,
199-
};
182+
it(
183+
'should return solution with lowest error',
184+
{
185+
// On macOS, `Math.sin` gives different results for some values.
186+
// Refs: https://issues.chromium.org/issues/333194604
187+
fails: os.platform() === 'darwin',
188+
},
189+
() => {
190+
const data = {
191+
x: [
192+
0, 0.6283185307179586, 1.2566370614359172, 1.8849555921538759,
193+
2.5132741228718345, 3.141592653589793, 3.7699111843077517,
194+
4.39822971502571, 5.026548245743669, 5.654866776461628,
195+
],
196+
y: [
197+
0, 1.902113032590307, 1.1755705045849465, -1.175570504584946,
198+
-1.9021130325903073, -4.898587196589413e-16, 1.902113032590307,
199+
1.1755705045849467, -1.1755705045849456, -1.9021130325903075,
200+
],
201+
};
202+
const options = {
203+
damping: 1.5,
204+
initialValues: [0.594398586701882, 0.3506424963635226],
205+
gradientDifference: 1e-2,
206+
maxIterations: 100,
207+
errorTolerance: 1e-2,
208+
};
200209

201-
const actual = levenbergMarquardt(data, sinFunction, options);
202-
const manualCalculatedError = data.x
203-
.map(sinFunction(actual.parameterValues))
204-
.reduce((acc, yHat, i) => acc + (data.y[i] - yHat) ** 2, 0);
205-
expect(actual.parameterError).toBeCloseTo(
206-
manualCalculatedError,
207-
options.errorTolerance,
208-
);
209-
expect(actual.parameterError).toBeCloseTo(15.5, options.errorTolerance);
210-
});
210+
const actual = levenbergMarquardt(data, sinFunction, options);
211+
const manualCalculatedError = data.x
212+
.map(sinFunction(actual.parameterValues))
213+
.reduce((acc, yHat, i) => acc + (data.y[i] - yHat) ** 2, 0);
214+
expect(actual.parameterError).toBeCloseTo(
215+
manualCalculatedError,
216+
options.errorTolerance,
217+
);
218+
expect(actual.parameterError).toBeCloseTo(15.5, options.errorTolerance);
219+
},
220+
);
211221
});
212222

213223
describe('"Real-world" problems (noisy data)', () => {

0 commit comments

Comments
 (0)