|
| 1 | +import { SpyInstance, describe, test, vi } from 'vitest'; |
| 2 | +import { pyramid, pyramidWithRecursion } from '../pyramid'; |
| 3 | + |
| 4 | +describe('Steps Algorithm', () => { |
| 5 | + let spy: SpyInstance; |
| 6 | + |
| 7 | + beforeEach(() => { |
| 8 | + spy = vi.spyOn(console, 'log').mockImplementation(() => {}); |
| 9 | + }); |
| 10 | + |
| 11 | + afterEach(() => { |
| 12 | + spy.mockRestore(); |
| 13 | + }); |
| 14 | + |
| 15 | + test('pyramid is a function', () => { |
| 16 | + expect(typeof pyramid).toEqual('function'); |
| 17 | + expect(typeof pyramidWithRecursion).toEqual('function'); |
| 18 | + }); |
| 19 | + |
| 20 | + test('prints a pryamid for n = 2', () => { |
| 21 | + pyramid(2); |
| 22 | + pyramidWithRecursion(2); |
| 23 | + expect(spy.mock.calls[0][0]).toEqual(' # '); |
| 24 | + expect(spy.mock.calls[1][0]).toEqual('###'); |
| 25 | + expect(spy.mock.calls.length).toEqual(4); |
| 26 | + }); |
| 27 | + |
| 28 | + test('prints a pryamid for n = 3', () => { |
| 29 | + pyramid(3); |
| 30 | + pyramidWithRecursion(3); |
| 31 | + expect(spy.mock.calls[0][0]).toEqual(' # '); |
| 32 | + expect(spy.mock.calls[1][0]).toEqual(' ### '); |
| 33 | + expect(spy.mock.calls[2][0]).toEqual('#####'); |
| 34 | + expect(spy.mock.calls.length).toEqual(6); |
| 35 | + }); |
| 36 | + |
| 37 | + test('prints a pryamid for n = 4', () => { |
| 38 | + pyramid(4); |
| 39 | + pyramidWithRecursion(4); |
| 40 | + expect(spy.mock.calls[0][0]).toEqual(' # '); |
| 41 | + expect(spy.mock.calls[1][0]).toEqual(' ### '); |
| 42 | + expect(spy.mock.calls[2][0]).toEqual(' ##### '); |
| 43 | + expect(spy.mock.calls[3][0]).toEqual('#######'); |
| 44 | + expect(spy.mock.calls.length).toEqual(8); |
| 45 | + }); |
| 46 | +}); |
0 commit comments