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

fix: GetEuclidGCD(0, 0) is 0 #1621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
raklaptudirm merged 1 commit into TheAlgorithms:master from vil02:cleanup_GetEuclidGCD
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion Maths/GetEuclidGCD.js
View file Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
26 changes: 18 additions & 8 deletions Maths/test/GetEuclidGCD.test.js
View file Open in desktop
Original file line number Diff line number Diff line change
@@ -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()
})
})

AltStyle によって変換されたページ (->オリジナル) /