Skip to content

Commit b5021f5

Browse files
committed
Fix atan unit tests: handle single-arg and two-arg cases, remove visual math test
1 parent 4a11290 commit b5021f5

File tree

3 files changed

+61
-18
lines changed

3 files changed

+61
-18
lines changed

test/unit/math/atan.js

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import trigonometry from '../../../src/math/trigonometry.js';
2+
import { vi } from 'vitest';
3+
import { assert } from 'chai';
4+
5+
suite('atan', function() {
6+
// Mock p5 object
7+
const mockP5 = {
8+
_validateParameters: vi.fn(),
9+
RADIANS: 'radians',
10+
DEGREES: 'degrees'
11+
};
12+
13+
// Mock prototype where trigonometry functions will be attached
14+
const mockP5Prototype = {};
15+
16+
beforeEach(function() {
17+
// Reset angle mode before each test
18+
mockP5Prototype._angleMode = mockP5.RADIANS;
19+
20+
// Mock angleMode setter
21+
mockP5Prototype.angleMode = function(mode) {
22+
this._angleMode = mode;
23+
};
24+
25+
// Initialize trigonometry functions on mock
26+
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+
};
41+
});
42+
43+
test('should return the correct value for atan(0.5) in radians', function() {
44+
mockP5Prototype.angleMode(mockP5.RADIANS);
45+
const expected = Math.atan(0.5);
46+
const actual = mockP5Prototype.atan(0.5);
47+
assert.closeTo(actual, expected, 1e-10);
48+
});
49+
50+
test('should return the correct value for atan(0.5) in degrees', function() {
51+
mockP5Prototype.angleMode(mockP5.DEGREES);
52+
const expected = Math.atan(0.5) * 180 / Math.PI;
53+
const actual = mockP5Prototype.atan(0.5);
54+
assert.closeTo(actual, expected, 1e-10);
55+
});
56+
57+
test('atan(y, x) outside strands returns undefined', function() {
58+
const result = mockP5Prototype.atan(1, 1);
59+
assert.isUndefined(result);
60+
});
61+
});

test/unit/spec.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,6 @@ var spec = {
5656
'webgl',
5757
'typography',
5858
'shape_modes',
59-
'math'
6059
]
6160
};
6261
document.write(

test/unit/visual/cases/math.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)