Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: Remove the automatic conversion from number to string. #2482

Merged
merged 1 commit into from
Mar 15, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/core/function/typed.js
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,6 @@ export const createTyped = /* #__PURE__ */ factory('typed', dependencies, functi

return new Complex(x, 0)
}
}, {
from: 'number',
to: 'string',
convert: function (x) {
return x + ''
}
}, {
from: 'BigNumber',
to: 'Complex',
Expand Down
8 changes: 1 addition & 7 deletions src/type/unit/Unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,7 @@ export const createUnitClass = /* #__PURE__ */ factory(name, dependencies, ({
this.units = u.units
this.dimensions = u.dimensions
} else {
this.units = [
{
unit: UNIT_NONE,
prefix: PREFIXES.NONE, // link to a list with supported prefixes
power: 0
}
]
this.units = []
this.dimensions = []
for (let i = 0; i < BASE_DIMENSIONS.length; i++) {
this.dimensions[i] = 0
Expand Down
5 changes: 5 additions & 0 deletions src/type/unit/function/unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ export const createUnitFunction = /* #__PURE__ */ factory(name, dependencies, ({
return new Unit(value, unit)
},

'number | BigNumber | Fraction': function (value) {
// dimensionless
return new Unit(value)
},

'Array | Matrix': function (x) {
return deepMap(x, this)
}
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/function/algebra/derivative.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ describe('derivative', function () {
it('should throw error for incorrect argument types', function () {
assert.throws(function () {
derivative('42', '42')
}, /TypeError: Unexpected type of argument in function derivative \(expected: string or SymbolNode or number or boolean, actual: ConstantNode, index: 1\)/)
}, /TypeError: Unexpected type of argument in function derivative \(expected: string or SymbolNode or boolean, actual: ConstantNode, index: 1\)/)

assert.throws(function () {
derivative('[1, 2; 3, 4]', 'x')
Expand All @@ -268,7 +268,7 @@ describe('derivative', function () {
it('should throw error if incorrect number of arguments', function () {
assert.throws(function () {
derivative('x + 2')
}, /TypeError: Too few arguments in function derivative \(expected: string or SymbolNode or number or boolean, index: 1\)/)
}, /TypeError: Too few arguments in function derivative \(expected: string or SymbolNode or boolean, index: 1\)/)

assert.throws(function () {
derivative('x + 2', 'x', {}, true, 42)
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/function/matrix/count.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ describe('count', function () {

it('should throw an error if called with an invalid number of arguments', function () {
assert.throws(function () { count() }, /TypeError: Too few arguments/)
assert.throws(function () { count(1, 2) }, /TypeError: Too many arguments/)
assert.throws(function () { count([1], 2) }, /TypeError: Too many arguments/)
})

it('should throw an error if called with invalid type of arguments', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/function/matrix/diag.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ describe('diag', function () {

it('should throw an error in case of wrong number of arguments', function () {
assert.throws(function () { math.diag() }, /TypeError: Too few arguments/)
assert.throws(function () { math.diag([], 2, 3, 4) }, /TypeError: Too many arguments/)
assert.throws(function () { math.diag([], 2, 'dense', 4) }, /TypeError: Too many arguments/)
})

it('should throw an error in case of invalid type of arguments', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/function/unit/to.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('to', function () {

it('should throw an error if called with a number', function () {
assert.throws(function () { math.to(5, unit('m')) }, TypeError)
assert.throws(function () { math.to(unit('5cm'), 2) }, /SyntaxError: "2" contains no units/)
assert.throws(function () { math.to(unit('5cm'), 2) }, TypeError)
})

it('should throw an error if called with a string', function () {
Expand Down
4 changes: 2 additions & 2 deletions test/unit-tests/type/matrix/function/matrix.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ describe('matrix', function () {
})

it('should throw an error if called with too many arguments', function () {
assert.throws(function () { matrix([], 3, 3, 7) }, /TypeError: Too many arguments/)
assert.throws(function () { matrix([], 'dense', 'number', 7) }, /TypeError: Too many arguments/)
})

it('should throw an error when called with an invalid storage format', function () {
assert.throws(function () { math.matrix([], 1) }, /TypeError: Unknown matrix type "1"/)
assert.throws(function () { math.matrix([], '1') }, /TypeError: Unknown matrix type "1"/)
})

it('should throw an error when called with an unknown storage format', function () {
Expand Down
2 changes: 1 addition & 1 deletion test/unit-tests/type/matrix/function/sparse.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ describe('sparse', function () {
})

it('should throw an error if called with too many arguments', function () {
assert.throws(function () { sparse([], 3, 3) }, /TypeError: Too many arguments/)
assert.throws(function () { sparse([], 'number', 3) }, /TypeError: Too many arguments/)
})

it('should LaTeX matrix', function () {
Expand Down