feat: Add complex numbers
No negation (and therefore no subtraction) since that needs self-reference.
This commit is contained in:
parent
b59a8c2ca9
commit
b82336e590
7 changed files with 71 additions and 0 deletions
21
test/custom.mjs
Normal file
21
test/custom.mjs
Normal file
|
@ -0,0 +1,21 @@
|
|||
import assert from 'assert'
|
||||
import typed from 'typed-function'
|
||||
import PocomathInstance from '../PocomathInstance.mjs'
|
||||
import * as numbers from '../number/all.mjs'
|
||||
import * as complex from '../complex/all.mjs'
|
||||
|
||||
const bw = new PocomathInstance('backwards')
|
||||
describe('A custom instance', () => {
|
||||
it("works when partially assembled", () => {
|
||||
bw.install(complex)
|
||||
assert.deepStrictEqual(bw.add(2, bw.complex(0, 3)), {re: 2, im: 3})
|
||||
})
|
||||
|
||||
it("can be assembled in any order", () => {
|
||||
bw.install(numbers)
|
||||
typed.addConversion({from: 'string', to: 'number', convert: x => +x})
|
||||
assert.strictEqual(bw.subtract(16, bw.add(3,4,2)), 7)
|
||||
assert.strictEqual(bw.negate('8'), -8)
|
||||
assert.deepStrictEqual(bw.add(bw.complex(1,3), 1), {re: 2, im: 3})
|
||||
})
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue