-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPattern_12.test.js
51 lines (48 loc) · 1.79 KB
/
Pattern_12.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 numberPyramid = require('../Pattern_12/Pattern_12');
describe('numberPyramid', () => {
it('should print the number pyramid for n=5', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
numberPyramid(5);
expect(consoleSpy).toHaveBeenCalledTimes(5);
expect(consoleSpy.mock.calls).toEqual([
['1 1 '],
['1 2 2 1 '],
['1 2 3 3 2 1 '],
['1 2 3 4 4 3 2 1 '],
['1 2 3 4 5 5 4 3 2 1 '],
]);
consoleSpy.mockRestore();
});
it('should print the number pyramid for n=7', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
numberPyramid(7);
expect(consoleSpy).toHaveBeenCalledTimes(7);
expect(consoleSpy.mock.calls).toEqual([
['1 1 '],
['1 2 2 1 '],
['1 2 3 3 2 1 '],
['1 2 3 4 4 3 2 1 '],
['1 2 3 4 5 5 4 3 2 1 '],
['1 2 3 4 5 6 6 5 4 3 2 1 '],
['1 2 3 4 5 6 7 7 6 5 4 3 2 1 '],
]);
consoleSpy.mockRestore();
});
it('should print the number pyramid for n=9', () => {
const consoleSpy = jest.spyOn(console, 'log').mockImplementation();
numberPyramid(9);
expect(consoleSpy).toHaveBeenCalledTimes(9);
expect(consoleSpy.mock.calls).toEqual([
['1 1 '],
['1 2 2 1 '],
['1 2 3 3 2 1 '],
['1 2 3 4 4 3 2 1 '],
['1 2 3 4 5 5 4 3 2 1 '],
['1 2 3 4 5 6 6 5 4 3 2 1 '],
['1 2 3 4 5 6 7 7 6 5 4 3 2 1 '],
['1 2 3 4 5 6 7 8 8 7 6 5 4 3 2 1 '],
['1 2 3 4 5 6 7 8 9 9 8 7 6 5 4 3 2 1 '],
]);
consoleSpy.mockRestore();
});
});