feat: Template implementations
This commit is contained in:
parent
1076c3c727
commit
fd3d6b2eb3
9 changed files with 67 additions and 23 deletions
|
@ -21,12 +21,14 @@ describe('The default full pocomath instance "math"', () => {
|
|||
|
||||
it('can subtract numbers', () => {
|
||||
assert.strictEqual(math.subtract(12, 5), 7)
|
||||
//assert.strictEqual(math.subtract(3n, 1.5), 1.5)
|
||||
})
|
||||
|
||||
it('can add numbers', () => {
|
||||
assert.strictEqual(math.add(3, 4), 7)
|
||||
assert.strictEqual(math.add(1.5, 2.5, 3.5), 7.5)
|
||||
assert.strictEqual(math.add(Infinity), Infinity)
|
||||
assert.throws(() => math.add(3n, -1.5), TypeError)
|
||||
})
|
||||
|
||||
it('can negate numbers', () => {
|
||||
|
@ -55,10 +57,10 @@ describe('The default full pocomath instance "math"', () => {
|
|||
assert.deepStrictEqual(
|
||||
math.subtract(math.complex(1,1), math.complex(2,-2)),
|
||||
math.complex(-1,3))
|
||||
assert.strictEqual(math.negate(math.complex(3, 8)).im, -8)
|
||||
assert.deepStrictEqual(
|
||||
math.subtract(16, math.add(3, math.complex(0,4), 2)),
|
||||
math.complex(11, -4))
|
||||
assert.strictEqual(math.negate(math.complex(3, 8)).im, -8)
|
||||
})
|
||||
|
||||
it('handles bigints', () => {
|
||||
|
|
|
@ -3,6 +3,7 @@ import math from '../src/pocomath.mjs'
|
|||
import PocomathInstance from '../src/core/PocomathInstance.mjs'
|
||||
import * as numbers from '../src/number/all.mjs'
|
||||
import * as numberAdd from '../src/number/add.mjs'
|
||||
import {add as genericAdd} from '../src/generic/arithmetic.mjs'
|
||||
import * as complex from '../src/complex/all.mjs'
|
||||
import * as complexAdd from '../src/complex/add.mjs'
|
||||
import * as complexNegate from '../src/complex/negate.mjs'
|
||||
|
@ -66,6 +67,7 @@ describe('A custom instance', () => {
|
|||
const cherry = new PocomathInstance('cherry')
|
||||
cherry.install(numberAdd)
|
||||
await extendToComplex(cherry)
|
||||
cherry.install({add: genericAdd})
|
||||
/* Now we have an instance that supports addition for number and complex
|
||||
and little else:
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue