feat: Template types for Pocomath
Tuple<T> and a couple of functions on it are now working according to the target spec. As desired, no instantiations of a template type are made until some function that takes an instantiation is called.
This commit is contained in:
parent
a743337134
commit
b0fb004224
7 changed files with 190 additions and 44 deletions
|
@ -3,7 +3,26 @@ import math from '../../src/pocomath.mjs'
|
|||
|
||||
describe('tuple', () => {
|
||||
it('can be created and provide its length', () => {
|
||||
assert.strictEqual(math.length(math.tuple(3,5.2,2n)), 3)
|
||||
assert.strictEqual(math.length(math.tuple(3, 5.2, 2)), 3)
|
||||
})
|
||||
|
||||
it('does not allow unification by converting consecutive arguments', () => {
|
||||
assert.throws(() => math.tuple(3, 5.2, 2n), /TypeError.*unif/)
|
||||
// Hence, the order matters in a slightly unfortunate way,
|
||||
// but I think being a little ragged in these edge cases is OK:
|
||||
assert.throws(
|
||||
() => math.tuple(3, 2n, math.complex(5.2)),
|
||||
/TypeError.*unif/)
|
||||
assert.deepStrictEqual(
|
||||
math.tuple(3, math.complex(2n), 5.2),
|
||||
{elts: [math.complex(3), math.complex(2n), math.complex(5.2)]})
|
||||
})
|
||||
|
||||
it('can be tested for zero', () => {
|
||||
assert.strictEqual(math.isZero(math.tuple(0,1)), false)
|
||||
assert.strictEqual(math.isZero(math.tuple(0n,0n,0n,0n)), true)
|
||||
assert.strictEqual(math.isZero(math.tuple(0,0.001,0)), false)
|
||||
assert.strictEqual(math.isZero(math.tuple(0,math.complex(0,0))), true)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue