mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-04 07:29:47 +08:00

* Add prettier config * test: add test to check for absolute function * chore: es5 to es6 * test: add test to check mean function * test: add test for sum of digit * test: add test for factorial * test: add test for fibonnaci * test: add test for find HCF * test: add test for lcm * test: add gridget test * test: add test for mean square error * test: add test for modular binary exponentiation * test: add tests for palindrome * test: add test for pascals triangle * test: add tests for polynomial * test: add tests for prime check * test: add tests for reverse polish notation * test: add tests for sieve of eratosthenes * test: add tests for pi estimation monte carlo method * chore: move tests to test folder * chore: fix standardjs errors
38 lines
1.4 KiB
JavaScript
38 lines
1.4 KiB
JavaScript
import { Polynomial } from '../Polynomial'
|
|
|
|
describe('Polynomial', () => {
|
|
it('should not return a expression for zero', () => {
|
|
const polynomial = new Polynomial([0])
|
|
expect(polynomial.display()).toBe('')
|
|
})
|
|
it('should not return an expression for zero values', () => {
|
|
const polynomial = new Polynomial([0, 0, 0, 0, 0])
|
|
expect(polynomial.display()).toBe('')
|
|
})
|
|
it('should return an expression for single a non zero value', () => {
|
|
const polynomial = new Polynomial([9])
|
|
expect(polynomial.display()).toBe('(9)')
|
|
})
|
|
it('should return an expression for two values', () => {
|
|
const polynomial = new Polynomial([3, 2])
|
|
expect(polynomial.display()).toBe('(2x) + (3)')
|
|
})
|
|
it('should return an expression for values including zero', () => {
|
|
const polynomial = new Polynomial([0, 2])
|
|
expect(polynomial.display()).toBe('(2x)')
|
|
})
|
|
it('should return an expression and evaluate it', () => {
|
|
const polynomial = new Polynomial([1, 2, 3, 4])
|
|
expect(polynomial.display()).toBe('(4x^3) + (3x^2) + (2x) + (1)')
|
|
expect(polynomial.evaluate(2)).toEqual(49)
|
|
})
|
|
it('should evaluate 0 for zero values', () => {
|
|
const polynomial = new Polynomial([0, 0, 0, 0])
|
|
expect(polynomial.evaluate(5)).toEqual(0)
|
|
})
|
|
it('should evaluate for negative values', () => {
|
|
const polynomial = new Polynomial([-1, -3, -4, -7])
|
|
expect(polynomial.evaluate(-5)).toBe(789)
|
|
})
|
|
})
|