chore: add boolean test files omitted earlier
All checks were successful
/ test (pull_request) Successful in 18s

This commit is contained in:
Glen Whitney 2025-04-13 00:14:56 -07:00
parent 4b81fbe6e2
commit a7673216c1
2 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,25 @@
import assert from 'assert'
import math from '#nanomath'
import {Type} from '#core/Type.js'
const boolean = math.boolean
describe('boolean type functions', () => {
it('properly converts to boolean', () => {
assert.strictEqual(boolean(false), false)
assert.strictEqual(boolean(true), true)
assert.strictEqual(boolean(0), false)
assert.strictEqual(boolean(-0), false)
assert.strictEqual(boolean(NaN), false)
assert.strictEqual(boolean(Infinity), true)
assert.strictEqual(boolean(1e-30), true)
assert.strictEqual(boolean(undefined), false)
assert.strictEqual(boolean(), false)
assert.strictEqual(boolean(math.types.NumberT), true)
})
it('converts any type to boolean', () => {
for (const T in math.types) {
if (T instanceof Type) assert(boolean.resolve([T]))
}
})
})

14
src/boolean/type.js Normal file
View file

@ -0,0 +1,14 @@
import {BooleanT} from './BooleanT.js'
import {onType} from '#core/helpers.js'
import {Returns, Type, TypeOfTypes, Undefined} from '#core/Type.js'
import {NumberT} from '#number/NumberT.js'
const bool = f => Returns(BooleanT, f)
export const boolean = onType(
BooleanT, bool(p => p),
NumberT, bool(a => !!a),
TypeOfTypes, bool(() => true),
Undefined, bool(() => false),
[], bool(() => false)
)