So far, abs, add, norm, normsq, and sum are supported. To get them to work, also implements the following: * refactor: Use ReturnType function rather than just accessing .returns * feat: distinguish marking a function as a behavior from its return type * refactor: Rename `NotAType` to `Unknown` because it must be made closer to a bona fide type for the sake of inhomogeneous vectors * feat: make resolving a TypeDispatcher method on a type vector including `Unknown` into a no-op; that simplifies a number of generic behaviors * feat: add `haszero` method parallel to `hasnan` * feat: track the Vector nesting depth of Vector specializations
18 lines
671 B
JavaScript
18 lines
671 B
JavaScript
import assert from 'assert'
|
|
import math from '#nanomath'
|
|
import {ReturnType, 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(ReturnType(math.square.resolve([NumberT])), 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))
|
|
})
|
|
})
|