2022-03-25 09:03:20 +00:00
|
|
|
import assert from 'assert'
|
|
|
|
import math from '../picomath.js'
|
|
|
|
import picoInstance from '../picomathInstance.js'
|
2022-03-25 09:46:49 +00:00
|
|
|
import createNumbers from '../number/all.js'
|
|
|
|
import createNumber from '../number/number.js'
|
|
|
|
import createAdd from '../number/add.js'
|
2022-03-25 09:03:20 +00:00
|
|
|
import createComplex from '../complex/all.js'
|
2022-03-25 09:46:49 +00:00
|
|
|
import extendByComplex from '../complex/extendByComplex.js'
|
2022-03-25 09:03:20 +00:00
|
|
|
|
|
|
|
describe('Custom instances', () => {
|
|
|
|
it("doesn't matter what order you assemble", () => {
|
|
|
|
const bw = picoInstance('backwards')
|
|
|
|
createComplex(bw)
|
2022-03-25 09:46:49 +00:00
|
|
|
createNumbers(bw)
|
2022-03-25 09:03:20 +00:00
|
|
|
|
|
|
|
assert.strictEqual(bw.subtract(16, bw.add(3,4,2)), 7)
|
|
|
|
assert.strictEqual(bw.negate(bw.number('8')), -8)
|
|
|
|
assert.deepStrictEqual(bw.complex(2,3), {re: 2, im: 3})
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
bw.subtract(16, bw.add(3, bw.complex(0,4), 2)),
|
|
|
|
math.complex(11, -4)) // note both instances coexist
|
|
|
|
assert.deepStrictEqual(bw.negate(math.complex(3, '8')).im, -8)
|
|
|
|
})
|
2022-03-25 09:46:49 +00:00
|
|
|
|
|
|
|
it("can selectively import in cute ways", async function () {
|
|
|
|
const cherry = picoInstance('cherry')
|
|
|
|
createNumber(cherry)
|
|
|
|
createAdd(cherry)
|
|
|
|
await extendByComplex(cherry)
|
|
|
|
// Now we have an instance that supports addition for number and complex
|
|
|
|
// and little else:
|
|
|
|
assert.strictEqual(cherry.add(3, 4, 2), 9)
|
|
|
|
assert.deepStrictEqual(
|
|
|
|
cherry.add(cherry.complex(3, 3), 4, cherry.complex(2, 2)),
|
|
|
|
math.complex(9,5))
|
|
|
|
assert.strictEqual('subtract' in cherry, false)
|
|
|
|
assert.strictEqual('negate' in cherry, false)
|
|
|
|
})
|
2022-03-25 09:03:20 +00:00
|
|
|
})
|