picomath/test/_picomath.js
Glen Whitney 00a7f79552 feat(poortf): add concept of 'author' to an imp of a TF
And make it so that if the same author adds imps again, they replace
  the previous imps from that author.

  Use this feature to avoid the explicit check for double-inclusion in
  subtract, and test it worked.
2022-03-25 11:31:06 -07:00

28 lines
964 B
JavaScript

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')
})
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)
})
it('does not double-define subtract', () => {
assert.deepStrictEqual(math.subtract.imps.length, 1)
})
})