Skip to content

Commit

Permalink
fix: #3074 improve error message when using function max in `deriva…
Browse files Browse the repository at this point in the history
…tive`
  • Loading branch information
josdejong committed Oct 11, 2023
1 parent 4a62e7c commit 7b9defb
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 4 deletions.
1 change: 0 additions & 1 deletion AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,5 @@ BuildTools <[email protected]>
Anik Patel <[email protected]>
Vrushaket Chaudhari <[email protected]>
Praise Nnamonu <[email protected]>
vrushaket <[email protected]>

# Generated by tools/update-authors.js
1 change: 1 addition & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

- Fix #3025: improve handling of matrices and error handling
in function `corr` (#3030). Thanks @vrushaket.
- Fix #3074: improve error message when using function `max` in `derivative`.


# 2023-09-20, 11.11.1
Expand Down
3 changes: 2 additions & 1 deletion src/function/algebra/derivative.js
Original file line number Diff line number Diff line change
Expand Up @@ -765,7 +765,8 @@ export const createDerivative = /* #__PURE__ */ factory(name, dependencies, ({
}

node.compile().evaluate()
throw new Error('Expected TypeError, but none found')

throw new Error('Function "' + node.name + '" is not supported by derivative, or a wrong number of arguments is passed')
}

/**
Expand Down
8 changes: 6 additions & 2 deletions test/unit-tests/function/algebra/derivative.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,8 +238,12 @@ describe('derivative', function () {
})

it('should throw error if expressions contain unsupported operators or functions', function () {
assert.throws(function () { derivative('x << 2', 'x') }, /Error: Operator "<<" is not supported by derivative/)
assert.throws(function () { derivative('subset(x)', 'x') }, /Error: Function "subset" is not supported by derivative/)
assert.throws(function () { derivative('x << 2', 'x') }, /Error: Operator "<<" is not supported by derivative, or a wrong number of arguments is passed/)
assert.throws(function () { derivative('subset(x)', 'x') }, /Error: Function "subset" is not supported by derivative, or a wrong number of arguments is passed/)
assert.throws(function () { derivative('max(x)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/)
assert.throws(function () { derivative('max(x, y)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/)
assert.throws(function () { derivative('max(x, 1)', 'x') }, /Error: Function "max" is not supported by derivative, or a wrong number of arguments is passed/)
assert.throws(function () { derivative('add(2,3,x)', 'x') }, /Error: Function "add" is not supported by derivative, or a wrong number of arguments is passed/)
})

it('should have controlled behavior on arguments errors', function () {
Expand Down

0 comments on commit 7b9defb

Please sign in to comment.