2022-03-25 07:49:03 +00:00
|
|
|
import assert from 'assert'
|
|
|
|
import math from '../picomath.js'
|
|
|
|
|
|
|
|
describe('The default full picomath instance "math"', () => {
|
|
|
|
it('performs basic arithmetic operations', () => {
|
|
|
|
assert.strictEqual(math.subtract(16, math.add(3,4,2)), 7)
|
|
|
|
assert.strictEqual(math.negate(math.number('8')), -8)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('can be extended', () => {
|
|
|
|
math('add', [args => typeof args[0] === 'string',
|
|
|
|
(...addends) => addends.reduce((x,y) => x+y, '')])
|
|
|
|
assert.strictEqual(math.add('Kilroy',' is here'), 'Kilroy is here')
|
|
|
|
})
|
2022-03-25 08:54:20 +00:00
|
|
|
|
|
|
|
it('handles complex numbers', () => {
|
|
|
|
assert.deepStrictEqual(math.complex(2,3), {re: 2, im: 3})
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
math.subtract(16, math.add(3, math.complex(0,4), 2)),
|
|
|
|
math.complex(11, -4))
|
|
|
|
assert.deepStrictEqual(math.negate(math.complex(3, '8')).im, -8)
|
|
|
|
})
|
2022-03-25 18:31:06 +00:00
|
|
|
|
|
|
|
it('does not double-define subtract', () => {
|
|
|
|
assert.deepStrictEqual(math.subtract.imps.length, 1)
|
|
|
|
})
|
2022-03-25 07:49:03 +00:00
|
|
|
})
|