nanomath/src/generic/__test__/arithmetic.spec.js

19 lines
655 B
JavaScript
Raw Normal View History

import assert from 'assert'
import math from '#nanomath'
import {ReturnTyping} from '#core/Type.js'
const {Complex, NumberT} = math.types
describe('generic arithmetic', () => {
it('squares anything', () => {
const sq = math.square
assert.strictEqual(sq(7), 49)
assert.strictEqual(math.square.resolve([NumberT]).returns, NumberT)
assert.deepStrictEqual(sq(math.complex(3, 4)), math.complex(-7, 24))
const eyes = math.complex(0, 2)
assert.strictEqual(sq(eyes), -4)
const sqFull = math.square.resolve(Complex(NumberT), ReturnTyping.full)
assert.deepStrictEqual(sqFull(eyes), math.complex(-4, 0))
})
})