nanomath/src/boolean/__test__/BooleanT.spec.js
Glen Whitney 95d81d0338
All checks were successful
/ test (push) Successful in 18s
feat: Implement Vector type (#28)
The Vector type is simply a generic type for built-in JavaScript Arrays. The parameter type is the type of all of the entries of the Array. The Vector type also supports inhomogeneous arrays by using the special type `Unknown` as the argument type, but note that when computing with inhomogeneous arrays, method dispatch must be performed separately for every entry in a calculation, making all operations considerably slower than on homogeneous Vector instances.

Note also that arithmetic operations on nested Vectors, e.g. `Vector(Vector(NumberT))` are defined so as to interpret such entities as ordinary matrices, represented in row-major format (i.e., the component `Vector(NumberT)` items of such an entity are the _rows_ of the matrix.

Reviewed-on: #28
Co-authored-by: Glen Whitney <glen@studioinfinity.org>
Co-committed-by: Glen Whitney <glen@studioinfinity.org>
2025-05-07 00:03:49 +00:00

24 lines
881 B
JavaScript

import assert from 'assert'
import {BooleanT} from '../BooleanT.js'
import math from '#nanomath'
describe('BooleanT Type', () => {
it('correctly recognizes booleans', () => {
assert(BooleanT.test(true))
assert(BooleanT.test(false))
assert(!BooleanT.test(null))
assert(!BooleanT.test(1))
})
it('autoconverts to number type', () => {
assert.strictEqual(math.abs(false), 0)
assert.strictEqual(math.normsq(true), 1)
assert.strictEqual(math.add(true, true), 2)
assert.strictEqual(math.divide(false, true), 0)
assert.strictEqual(math.cbrt(true), 1)
assert.strictEqual(math.invert(true), 1)
assert.strictEqual(math.multiply(false, false), 0)
assert.strictEqual(math.negate(false), -0)
assert.strictEqual(math.subtract(false, true), -1)
assert.strictEqual(math.quotient(true, true), 1)
})
})