-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathzeroFill.test.js
More file actions
30 lines (26 loc) · 1 KB
/
zeroFill.test.js
File metadata and controls
30 lines (26 loc) · 1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
const ZeroFill = require('../src/zeroFill');
describe('ZeroFill', () => {
it('should pad with leading zeros to reach the specified width', () => {
const number = 42;
const width = 5;
const zeroFillInstance = new ZeroFill(number, width);
expect(zeroFillInstance.execute()).toBe('00042');
});
it('should handle negative numbers', () => {
const number = -7;
const width = 4;
const zeroFillInstance = new ZeroFill(number, width);
expect(zeroFillInstance.execute()).toBe('00-7');
});
it('should handle wider width than the number length', () => {
const number = 123;
const width = 3;
const zeroFillInstance = new ZeroFill(number, width);
expect(zeroFillInstance.execute()).toBe('123');
});
it('should handle non-numeric inputs', () => {
const number = 'test';
const width = 2;
expect(() => new ZeroFill(number, width)).toThrowError('Both inputs must be numbers.');
});
});