-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern_03.test.js
51 lines (48 loc) · 1.46 KB
/
Pattern_03.test.js
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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
const rightTriangleNumberPattern = require('../Pattern_03/Pattern_03');
describe('rightTriangleNumberPattern', () => {
it('should print the right triangle number pattern for n=5', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
rightTriangleNumberPattern(5);
expect(consoleSpy).toHaveBeenCalledTimes(5);
expect(consoleSpy.mock.calls).toEqual([
['1 '],
['1 2 '],
['1 2 3 '],
['1 2 3 4 '],
['1 2 3 4 5 '],
]);
consoleSpy.mockRestore();
});
it('should print the right triangle number pattern for n=7', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
rightTriangleNumberPattern(7);
expect(consoleSpy).toHaveBeenCalledTimes(7);
expect(consoleSpy.mock.calls).toEqual([
['1 '],
['1 2 '],
['1 2 3 '],
['1 2 3 4 '],
['1 2 3 4 5 '],
['1 2 3 4 5 6 '],
['1 2 3 4 5 6 7 '],
]);
consoleSpy.mockRestore();
});
it('should print the right triangle number pattern for n=9', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
rightTriangleNumberPattern(9);
expect(consoleSpy).toHaveBeenCalledTimes(9);
expect(consoleSpy.mock.calls).toEqual([
['1 '],
['1 2 '],
['1 2 3 '],
['1 2 3 4 '],
['1 2 3 4 5 '],
['1 2 3 4 5 6 '],
['1 2 3 4 5 6 7 '],
['1 2 3 4 5 6 7 8 '],
['1 2 3 4 5 6 7 8 9 '],
]);
consoleSpy.mockRestore();
});
});