Skip to content

Commit b2e4e34

Browse files
committed
Update atan unit tests to comply with maintainer feedback
1 parent b5021f5 commit b2e4e34

File tree

1 file changed

+4
-32
lines changed

1 file changed

+4
-32
lines changed

test/unit/math/atan.js

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,33 @@
11
import trigonometry from '../../../src/math/trigonometry.js';
2-
import { vi } from 'vitest';
32
import { assert } from 'chai';
43

54
suite('atan', function() {
6-
// Mock p5 object
75
const mockP5 = {
8-
_validateParameters: vi.fn(),
96
RADIANS: 'radians',
10-
DEGREES: 'degrees'
7+
DEGREES: 'degrees',
8+
_validateParameters: () => {}
119
};
12-
13-
// Mock prototype where trigonometry functions will be attached
1410
const mockP5Prototype = {};
1511

1612
beforeEach(function() {
17-
// Reset angle mode before each test
1813
mockP5Prototype._angleMode = mockP5.RADIANS;
19-
20-
// Mock angleMode setter
2114
mockP5Prototype.angleMode = function(mode) {
2215
this._angleMode = mode;
2316
};
24-
25-
// Initialize trigonometry functions on mock
2617
trigonometry(mockP5, mockP5Prototype);
27-
28-
// Save original atan (from trigonometry)
29-
const originalAtan = mockP5Prototype.atan;
30-
31-
// Override atan to handle one-arg and two-arg correctly
32-
mockP5Prototype.atan = function(...args) {
33-
if (args.length === 1) {
34-
// Single-argument: use the original (already handles radians/degrees)
35-
return originalAtan.call(this, args[0]);
36-
} else if (args.length === 2) {
37-
// Two-argument atan(y, x) is GLSL-only, return undefined outside strands
38-
return undefined;
39-
}
40-
};
4118
});
4219

4320
test('should return the correct value for atan(0.5) in radians', function() {
4421
mockP5Prototype.angleMode(mockP5.RADIANS);
45-
const expected = Math.atan(0.5);
22+
const expected = 0.4636476090008061; // pre-calculated value
4623
const actual = mockP5Prototype.atan(0.5);
4724
assert.closeTo(actual, expected, 1e-10);
4825
});
4926

5027
test('should return the correct value for atan(0.5) in degrees', function() {
5128
mockP5Prototype.angleMode(mockP5.DEGREES);
52-
const expected = Math.atan(0.5) * 180 / Math.PI;
29+
const expected = 26.56505117707799; // pre-calculated value
5330
const actual = mockP5Prototype.atan(0.5);
5431
assert.closeTo(actual, expected, 1e-10);
5532
});
56-
57-
test('atan(y, x) outside strands returns undefined', function() {
58-
const result = mockP5Prototype.atan(1, 1);
59-
assert.isUndefined(result);
60-
});
6133
});

0 commit comments

Comments
 (0)