Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc067a34

Browse files
authored
fix:GetEuclidGCD(0, 0) is0 (TheAlgorithms#1621)
1 parent0e0cf98 commitc067a34

File tree

2 files changed

+18
-9
lines changed

2 files changed

+18
-9
lines changed

‎Maths/GetEuclidGCD.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ export function GetEuclidGCD(a, b) {
88
if(typeofa!=='number'||typeofb!=='number'){
99
thrownewTypeError('Arguments must be numbers')
1010
}
11-
if(a===0&&b===0)returnundefined// infinitely many numbers divide 0
1211
a=Math.abs(a)
1312
b=Math.abs(b)
1413
while(b!==0){

‎Maths/test/GetEuclidGCD.test.js

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,22 @@
11
import{GetEuclidGCD}from'../GetEuclidGCD'
22

3-
functiontestEuclidGCD(n,m,expected){
4-
test('Testing on '+n+' and '+m+'!',()=>{
5-
expect(GetEuclidGCD(n,m)).toBe(expected)
3+
describe('GetEuclidGCD',()=>{
4+
it.each([
5+
[5,20,5],
6+
[109,902,1],
7+
[290,780,10],
8+
[104,156,52],
9+
[0,100,100],
10+
[-5,50,5],
11+
[0,0,0],
12+
[1,1234567,1]
13+
])('returns correct result for %i and %j',(inputA,inputB,expected)=>{
14+
expect(GetEuclidGCD(inputA,inputB)).toBe(expected)
15+
expect(GetEuclidGCD(inputB,inputA)).toBe(expected)
616
})
7-
}
817

9-
testEuclidGCD(5,20,5)
10-
testEuclidGCD(109,902,1)
11-
testEuclidGCD(290,780,10)
12-
testEuclidGCD(104,156,52)
18+
it('should throw when any of the inputs is not a number',()=>{
19+
expect(()=>GetEuclidGCD('1',2)).toThrowError()
20+
expect(()=>GetEuclidGCD(1,'2')).toThrowError()
21+
})
22+
})

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp