Added Extended Euclidean Algorithm (ExtendedEuclideanGCD.js) to Maths folder, along with relevant test

This commit is contained in:
VinWare
2021-10-21 14:58:12 +05:30
parent f2573ca0d4
commit fe56f54f82
2 changed files with 76 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
import { extendedEuclideanGCD } from '../ExtendedEuclideanGCD'
describe('extendedEuclideanGCD', () => {
it('should return valid values in order for positive arguments', () => {
expect(extendedEuclideanGCD(240, 46)).toMatchObject([2, -9, 47])
expect(extendedEuclideanGCD(46, 240)).toMatchObject([2, 47, -9])
})
it('should give error on non-positive arguments', () => {
expect(() => extendedEuclideanGCD(0,240)).toThrowError(new TypeError('Must be positive numbers'))
expect(() => extendedEuclideanGCD(46,-240)).toThrowError(new TypeError('Must be positive numbers'))
})
it('should give error on non-numeric arguments', () => {
expect(() => extendedEuclideanGCD('240',46)).toThrowError(new TypeError('Not a Number'));
expect(() => extendedEuclideanGCD([240,46])).toThrowError(new TypeError('Not a Number'));
})
})