Skip to content

Commit d3d975c

Browse files
authored
tests(library/math): specs how co-primes should be handled in greatestCommonDivisor (#572)
- sourced from [the relevant section in this article](https://en.wikipedia.org/wiki/Greatest_common_divisor#Coprime_numbers)
1 parent 7cd7a8c commit d3d975c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/library/math/operator/constructive/greatestCommonDivisor.test.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,28 @@ describe(greatestCommonDivisor, () => {
184184
expect(greatestCommonDivisor(primeA, primeA)).toBe(primeA);
185185
});
186186

187-
it.todo('should return identity factor for co-prime operands');
187+
const identityFactor = 1;
188+
189+
const neighboringPrimes = [
190+
primeA,
191+
primeB,
192+
] as const;
193+
194+
const coPrimePairs = [
195+
neighboringPrimes,
196+
neighboringPrimes.map($0 => $0 * $0) as [number, number],
197+
];
198+
199+
it.each(coPrimePairs)('should return identity factor for co-prime operands', (...eachCoPrimePair) => {
200+
expect.assertions(1);
201+
202+
expect(
203+
greatestCommonDivisor(
204+
identityFactor * eachCoPrimePair[0],
205+
identityFactor * eachCoPrimePair[1],
206+
),
207+
).toBe(identityFactor);
208+
});
188209

189210
it.todo('should extract a common factor applied to two distinct prime numbers');
190211
});

0 commit comments

Comments
 (0)