Skip to content

Commit 649b7b5

Browse files
authored
tests(library/math): completes spec for in-scope failure mode of greatestCommonDivisor (#545)
- see [commits](https://github.com/nod-ai/shark-ui/pull/545/commits) for details
1 parent e64fcdb commit 649b7b5

File tree

1 file changed

+30
-3
lines changed

1 file changed

+30
-3
lines changed

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

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import {
44
expect,
55
} from 'vitest';
66

7+
import Attempt from '@/library/Attempt';
8+
79
import {
810
numberTaxonomy,
911
} from '../../numberTaxonomy';
@@ -72,8 +74,10 @@ describe(greatestCommonDivisor, () => {
7274

7375
describe('when generated', () => {
7476
describe('due to fractional operands', () => {
77+
const eulers = numberTaxonomy.fractional.transcendental; // c-spell:words eulers
78+
7579
const combosOfFractionalNumbers = symmetricPairCombos({
76-
of : numberTaxonomy.fractional.transcendental,
80+
of : eulers,
7781
filler: primeA,
7882
});
7983

@@ -83,9 +87,32 @@ describe(greatestCommonDivisor, () => {
8387
expect(() => greatestCommonDivisor(...$0)).toThrow(Error);
8488
});
8589

86-
it.todo('should safely propagate the error');
90+
it.each(combosOfFractionalNumbers)('should safely propagate the error', (...$0) => {
91+
expect.assertions(1);
92+
93+
expect(() => greatestCommonDivisor(...$0)).toThrow(Attempt.NonActionableError);
94+
});
95+
96+
const fractionalCombosWithMessage = [
97+
{
98+
numbers: [eulers, primeA] as const,
99+
message: 'Left operand must be whole.',
100+
},
101+
{
102+
numbers: [eulers, eulers] as const,
103+
message: 'Left operand must be whole.',
104+
},
105+
{
106+
numbers: [primeA, eulers] as const,
107+
message: 'Right operand must be whole.',
108+
},
109+
];
110+
111+
it.each(fractionalCombosWithMessage)('should communicate clearly with developers', ($0) => {
112+
expect.assertions(1);
87113

88-
it.todo('should communicate clearly with developers');
114+
expect(() => greatestCommonDivisor(...$0.numbers)).toThrow($0.message);
115+
});
89116
});
90117
});
91118
});

0 commit comments

Comments
 (0)