nanomath/src/generic/__test__/utils.spec.js
Glen Whitney aad62df8ac
All checks were successful
/ test (push) Successful in 17s
feat: methods on Complex (#24)
Adds all of the pocomath functions on Complex that do not depend on any unimplemented types or config properties, except quotient and roundquotient, where the design is murky. To get this working, adds some additional features:
  * Allows conversions to generic types, with the matched type
    determined from the return value of the built convertor
  * Adds predicate-based type patterns
  * Adds conversion from any non-complex type T to Complex(T)
  * Adds check for recursive loops in resolve (a key/signature depending on itself)

Reviewed-on: #24
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
2025-04-25 14:17:34 +00:00

25 lines
810 B
JavaScript

import assert from 'assert'
import math from '#nanomath'
import {NumberT} from '#number/NumberT.js'
describe('generic utility functions', () => {
it('tests whether an element is zero', () => {
const {isZero} = math
assert(!isZero(3))
assert(isZero(3e-16))
assert(isZero(false))
assert(!isZero(true))
assert(isZero(undefined))
assert(isZero(math.types.Complex(NumberT).zero))
assert(isZero(math.complex(-2e-16, 4e-17)))
assert(!isZero(math.complex(true)))
})
it('tests whether an element is real', () => {
const {isReal} = math
assert(isReal(Infinity))
assert(isReal(false))
assert(isReal(math.types.Complex(NumberT).one))
assert(isReal(math.complex(-3.25, 4e-16)))
assert(!isReal(math.complex(3, 4)))
})
})