Skip to content

Commit 4018555

Browse files
committed
fixes in dev-2.0
1 parent 60ef55e commit 4018555

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/core/friendly_errors/param_validator.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ function validateParams(p5, fn, lifecycles) {
6464
'Boolean': z.boolean(),
6565
'Function': z.function(),
6666
'Integer': z.number().int(),
67-
'Number': z.number(),
67+
'Number': z.number().or(z.literal(Infinity)).or(z.literal(-Infinity)),
6868
'Object': z.object({}),
6969
'String': z.string()
7070
};

test/unit/math/calculation.js

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,18 @@ suite('Calculation', function() {
299299
result = mockP5Prototype.max([10, 10]);
300300
assert.equal(result, 10);
301301
});
302+
test('should handle Infinity', function() {
303+
result = mockP5Prototype.max(3, Infinity);
304+
assert.equal(result, Infinity);
305+
});
306+
test('should handle -Infinity', function() {
307+
result = mockP5Prototype.max(3, -Infinity);
308+
assert.equal(result, 3);
309+
});
310+
test('should handle Infinity in array', function() {
311+
result = mockP5Prototype.max([3, Infinity, 5]);
312+
assert.equal(result, Infinity);
313+
});
302314
});
303315

304316
suite('p5.prototype.min', function() {
@@ -331,6 +343,18 @@ suite('Calculation', function() {
331343
result = mockP5Prototype.min([10, 10]);
332344
assert.equal(result, 10);
333345
});
346+
test('should handle Infinity', function() {
347+
result = mockP5Prototype.min(Infinity, 3);
348+
assert.equal(result, 3);
349+
});
350+
test('should handle -Infinity', function() {
351+
result = mockP5Prototype.min(3, -Infinity);
352+
assert.equal(result, -Infinity);
353+
});
354+
test('should handle -Infinity in array', function() {
355+
result = mockP5Prototype.min([3, -Infinity, 5]);
356+
assert.equal(result, -Infinity);
357+
});
334358
});
335359

336360
suite('p5.prototype.norm', function() {

0 commit comments

Comments
 (0)