diff --git a/Maths/GetEuclidGCD.js b/Maths/GetEuclidGCD.js index 5499057d78..31eeab42ec 100644 --- a/Maths/GetEuclidGCD.js +++ b/Maths/GetEuclidGCD.js @@ -8,7 +8,6 @@ export function GetEuclidGCD(a, b) { if (typeof a !== 'number' || typeof b !== 'number') { throw new TypeError('Arguments must be numbers') } - if (a === 0 && b === 0) return undefined // infinitely many numbers divide 0 a = Math.abs(a) b = Math.abs(b) while (b !== 0) { diff --git a/Maths/test/GetEuclidGCD.test.js b/Maths/test/GetEuclidGCD.test.js index 1639d9cb7f..a6c7cb22e6 100644 --- a/Maths/test/GetEuclidGCD.test.js +++ b/Maths/test/GetEuclidGCD.test.js @@ -1,12 +1,22 @@ import { GetEuclidGCD } from '../GetEuclidGCD' -function testEuclidGCD(n, m, expected) { - test('Testing on ' + n + ' and ' + m + '!', () => { - expect(GetEuclidGCD(n, m)).toBe(expected) +describe('GetEuclidGCD', () => { + it.each([ + [5, 20, 5], + [109, 902, 1], + [290, 780, 10], + [104, 156, 52], + [0, 100, 100], + [-5, 50, 5], + [0, 0, 0], + [1, 1234567, 1] + ])('returns correct result for %i and %j', (inputA, inputB, expected) => { + expect(GetEuclidGCD(inputA, inputB)).toBe(expected) + expect(GetEuclidGCD(inputB, inputA)).toBe(expected) }) -} -testEuclidGCD(5, 20, 5) -testEuclidGCD(109, 902, 1) -testEuclidGCD(290, 780, 10) -testEuclidGCD(104, 156, 52) + it('should throw when any of the inputs is not a number', () => { + expect(() => GetEuclidGCD('1', 2)).toThrowError() + expect(() => GetEuclidGCD(1, '2')).toThrowError() + }) +}) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy