Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update unit tests for gcd function
- add more tests to cover edge cases and different scenarios - delete incorrect test (gcd(1, 0) = 0)
  • Loading branch information
os-moussao committed Dec 9, 2023
commit adaaaf4122a891c3b26f670e09cb593d7491eecd
26 changes: 19 additions & 7 deletions test/ts/algorithms/math/gcd.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,26 @@ import { expect } from 'chai';
import { gcd } from '../../../../src/ts/index';

describe('GCD', () => {
it('returns the correct GCD for positive numbers', () => {
expect(gcd(8, 12)).to.equal(4);
expect(gcd(15, 25)).to.equal(5);
expect(gcd(21, 28)).to.equal(7);
});

it('returns the correct GCD for negative numbers', () => {
expect(gcd(-8, 12)).to.equal(4);
expect(gcd(15, -25)).to.equal(5);
expect(gcd(-21, -28)).to.equal(7);
});

it('returns the gcd between two numbers', () => {
it('returns the correct GCD when one of the numbers is 0', () => {
expect(gcd(0, -12)).to.equal(12);
expect(gcd(15, 0)).to.equal(15);
});

expect(gcd(1, 0)).to.equal(0);
expect(gcd(1, 1)).to.equal(1);
expect(gcd(2, 2)).to.equal(2);
expect(gcd(2, 4)).to.equal(2);
expect(gcd(2, 3)).to.equal(1);
expect(gcd(10, 1000)).to.equal(10);
it('returns 1 for co-prime numbers', () => {
expect(gcd(7, 22)).to.equal(1);
expect(gcd(11, 28)).to.equal(1);
expect(gcd(9, 16)).to.equal(1);
});
});