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))) }) })