pocomath/test/tuple/_native.mjs

29 lines
1.1 KiB
JavaScript
Raw Normal View History

import assert from 'assert'
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, 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)
})
})