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

26 lines
810 B
JavaScript
Raw Normal View History

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)))
})
})