fix: Separate typed instance for each PocomathInstance (#15)

Also starts each PocomathInstance with no types at all, and uses the new
  situation to eliminate the need for a Complex "base case".

  Resolves #14.
  Resolves #13.

Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Reviewed-on: #15
This commit is contained in:
Glen Whitney 2022-07-22 20:49:14 +00:00
parent ed71b15969
commit 0069597a76
25 changed files with 120 additions and 74 deletions

View file

@ -0,0 +1,13 @@
import assert from 'assert'
import PocomathInstance from '../../src/core/PocomathInstance.mjs'
describe('PocomathInstance', () => {
it('creates an instance that can define typed-functions', () => {
const pi = new PocomathInstance('dummy')
pi.install({'add': {'any,any': [[], (a,b) => a+b]}})
assert.strictEqual(pi.add(2,2), 4)
assert.strictEqual(pi.add('Kilroy', 17), 'Kilroy17')
assert.strictEqual(pi.add(1, undefined), NaN)
assert.throws(() => pi.add(1), TypeError)
})
})