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