Skip to content

Commit 8a9b879

Browse files
committed
Improve gematriya test coverage with zero and negative number
1 parent de5d536 commit 8a9b879

File tree

2 files changed

+14
-2
lines changed

2 files changed

+14
-2
lines changed

src/gematriya.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -68,8 +68,8 @@ function num2digits(num: number): number[] {
6868
export function gematriya(num: number | string): string {
6969
const num0 = <string>num;
7070
const num1 = parseInt(num0, 10);
71-
if (!num1) {
72-
throw new TypeError(`invalid parameter to gematriya ${num}`);
71+
if (!num1 || num1 < 0) {
72+
throw new TypeError(`invalid gematriya number: ${num}`);
7373
}
7474
let str = '';
7575
const thousands = Math.floor(num1 / 1000);

test/gematriya.spec.ts

+12
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,15 @@ test('gematriyaStrToNum-thousands', () => {
4949
expect(gematriyaStrToNum('א׳קכ״ג')).toBe(1123);
5050
expect(gematriyaStrToNum('ז׳ז׳')).toBe(7007);
5151
});
52+
53+
test('throws-0', () => {
54+
expect(() => {
55+
gematriya(NaN);
56+
}).toThrow('invalid gematriya number: NaN');
57+
expect(() => {
58+
gematriya(0);
59+
}).toThrow('invalid gematriya number: 0');
60+
expect(() => {
61+
gematriya(-34);
62+
}).toThrow('invalid gematriya number: -34');
63+
});

0 commit comments

Comments
 (0)