2025-04-08 23:25:01 +00:00
|
|
|
import assert from 'assert'
|
|
|
|
import math from '#nanomath'
|
2025-05-03 19:59:44 -07:00
|
|
|
import {ReturnType, ReturnTyping} from '#core/Type.js'
|
2025-04-28 16:29:33 +00:00
|
|
|
|
|
|
|
const {Complex, NumberT} = math.types
|
2025-04-08 23:25:01 +00:00
|
|
|
|
|
|
|
describe('generic arithmetic', () => {
|
|
|
|
it('squares anything', () => {
|
2025-04-28 16:29:33 +00:00
|
|
|
const sq = math.square
|
|
|
|
assert.strictEqual(sq(7), 49)
|
2025-05-03 19:59:44 -07:00
|
|
|
assert.strictEqual(ReturnType(math.square.resolve([NumberT])), NumberT)
|
2025-04-28 16:29:33 +00:00
|
|
|
assert.deepStrictEqual(sq(math.complex(3, 4)), math.complex(-7, 24))
|
|
|
|
const eyes = math.complex(0, 2)
|
|
|
|
assert.strictEqual(sq(eyes), -4)
|
|
|
|
const sqFull = math.square.resolve(Complex(NumberT), ReturnTyping.full)
|
|
|
|
assert.deepStrictEqual(sqFull(eyes), math.complex(-4, 0))
|
2025-04-08 23:25:01 +00:00
|
|
|
})
|
|
|
|
})
|