feat(floor): Provide example of op-centric organization
This commit is contained in:
parent
fe54bc6004
commit
7d1a435aa0
11 changed files with 65 additions and 8 deletions
|
@ -3,12 +3,12 @@ import PocomathInstance from '../src/core/PocomathInstance.mjs'
|
|||
import math from '../src/pocomath.mjs'
|
||||
|
||||
describe('The default full pocomath instance "math"', () => {
|
||||
it('has no undefined types', () => {
|
||||
it('has no unexpected undefined types', () => {
|
||||
const undef = math.undefinedTypes()
|
||||
if (undef.length) {
|
||||
console.log('Probable typo: found undefined types', undef)
|
||||
console.log('NOTE: Found undefined types', undef)
|
||||
}
|
||||
assert.strictEqual(undef.length, 0)
|
||||
assert.strictEqual(undef.length, 1) // Mentioning 'Fraction' but not using
|
||||
})
|
||||
|
||||
it('has a built-in typeOf operator', () => {
|
||||
|
|
|
@ -64,4 +64,8 @@ describe('bigint', () => {
|
|||
assert.strictEqual(math.lcm(0n, 0n), 0n)
|
||||
})
|
||||
|
||||
it('allows floor as a no-op', () => {
|
||||
assert.strictEqual(math.floor(-333n), -333n)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -51,4 +51,12 @@ describe('complex', () => {
|
|||
math.complex(4n, 5n))
|
||||
})
|
||||
|
||||
it('computes floor', () => {
|
||||
assert.deepStrictEqual(
|
||||
math.floor(math.complex(19, 22.7)),
|
||||
math.complex(19, 22))
|
||||
const gi = math.complex(-1n, 1n)
|
||||
assert.strictEqual(math.floor(gi), gi) // literally a no-op
|
||||
})
|
||||
|
||||
})
|
||||
|
|
|
@ -38,12 +38,20 @@ describe('A custom instance', () => {
|
|||
const pm = new PocomathInstance('piecemeal')
|
||||
pm.install(numbers)
|
||||
assert.strictEqual(pm.subtract(5, 10), -5)
|
||||
assert.strictEqual(pm.floor(3.7), 3)
|
||||
assert.throws(() => pm.floor(10n), TypeError)
|
||||
pm.install(complexAdd)
|
||||
pm.install(complexNegate)
|
||||
pm.install(complexComplex)
|
||||
// Should be enough to allow complex subtraction, as subtract is generic:
|
||||
assert.deepStrictEqual(
|
||||
pm.subtract({re:5, im:0}, {re:10, im:1}), {re:-5, im: -1})
|
||||
pm.subtract(pm.complex(5, 0), pm.complex(10, 1)),
|
||||
math.complex(-5, -1))
|
||||
// And now floor has been activated for Complex as well, since the type
|
||||
// is present
|
||||
assert.deepStrictEqual(
|
||||
pm.floor(math.complex(1.9, 0)),
|
||||
math.complex(1))
|
||||
})
|
||||
|
||||
it("can defer definition of (even used) types", () => {
|
||||
|
|
|
@ -37,4 +37,10 @@ describe('number', () => {
|
|||
assert.ok(math.largerEq(12.5, math.divide(25,2)))
|
||||
})
|
||||
|
||||
it('Computes floor', () => {
|
||||
assert.strictEqual(math.floor(7), 7)
|
||||
assert.strictEqual(math.floor(6.99), 6)
|
||||
assert.strictEqual(math.floor(1-1e-13), 1)
|
||||
})
|
||||
|
||||
})
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue