feat(polynomialRoot): Progress commit, quadratic implemented
This commit is contained in:
parent
de52c041e5
commit
c4b1ac9045
9 changed files with 422 additions and 163 deletions
34
test/complex/_polynomialRoot.mjs
Normal file
34
test/complex/_polynomialRoot.mjs
Normal file
|
@ -0,0 +1,34 @@
|
|||
import assert from 'assert'
|
||||
import math from '../../src/pocomath.mjs'
|
||||
|
||||
describe('polynomialRoot', () => {
|
||||
it('should solve a linear equation with real coefficients', function () {
|
||||
assert.deepEqual(math.polynomialRoot(6, 3), math.tuple(-2))
|
||||
assert.deepEqual(
|
||||
math.polynomialRoot(math.complex(-3, 2), 2),
|
||||
math.tuple(math.complex(1.5, -1)))
|
||||
assert.deepEqual(
|
||||
math.polynomialRoot(math.complex(3, 1), math.complex(-1, -1)),
|
||||
math.tuple(math.complex(2, -1)))
|
||||
})
|
||||
// Should be safe now to capture the functions:
|
||||
const complex = math.complex
|
||||
const pRoot = math.polynomialRoot
|
||||
const tup = math.tuple
|
||||
it('should solve a quadratic equation with a double root', function () {
|
||||
assert.deepEqual(pRoot(4, 4, 1), tup(-2))
|
||||
assert.deepEqual(
|
||||
pRoot(complex(0, 2), complex(2, 2), 1), tup(complex(-1, -1)))
|
||||
})
|
||||
it('should solve a quadratic with two distinct roots', function () {
|
||||
assert.deepEqual(pRoot(-3, 2, 1), tup(1, -3))
|
||||
assert.deepEqual(pRoot(-2, 0, 1), tup(math.sqrt(2), -math.sqrt(2)))
|
||||
assert.deepEqual(
|
||||
pRoot(4, 2, 1),
|
||||
tup(complex(-1, math.sqrt(3)), complex(-1, -math.sqrt(3))))
|
||||
assert.deepEqual(
|
||||
pRoot(complex(3, 1), -3, 1), tup(complex(1, 1), complex(2, -1)))
|
||||
})
|
||||
|
||||
|
||||
})
|
Loading…
Add table
Add a link
Reference in a new issue