mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2026-03-13 15:21:15 +08:00
Added Extended Euclidean Algorithm (ExtendedEuclideanGCD.js) to Maths folder, along with relevant test
This commit is contained in:
16
Maths/test/ExtendedEuclideanGCD.test.js
Normal file
16
Maths/test/ExtendedEuclideanGCD.test.js
Normal 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'));
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user