From 4e7a15694bd400e032330dad781bb9ae5e504773 Mon Sep 17 00:00:00 2001 From: YATIN KATHURIA <47096348+Yatin-kathuria@users.noreply.github.com> Date: Mon, 22 Nov 2021 22:23:48 +0530 Subject: [PATCH] merge: add test case and description (#842) --- Dynamic-Programming/ClimbingStairs.js | 11 +++++++---- .../tests/ClimbingStairs.test.js | 19 +++++++++++++++++++ 2 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 Dynamic-Programming/tests/ClimbingStairs.test.js diff --git a/Dynamic-Programming/ClimbingStairs.js b/Dynamic-Programming/ClimbingStairs.js index e89409e1e..dccc0c4db 100644 --- a/Dynamic-Programming/ClimbingStairs.js +++ b/Dynamic-Programming/ClimbingStairs.js @@ -1,7 +1,10 @@ -/* - * You are climbing a stair case. It takes n steps to reach to the top. - * Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? -*/ +/** + * @function ClimbStairs + * @description You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? + * @param {Integer} n - The input integer + * @return {Integer} distinct ways can you climb to the top. + * @see [Climb_Stairs](https://www.geeksforgeeks.org/count-ways-reach-nth-stair/) + */ const climbStairs = (n) => { let prev = 0 diff --git a/Dynamic-Programming/tests/ClimbingStairs.test.js b/Dynamic-Programming/tests/ClimbingStairs.test.js new file mode 100644 index 000000000..382c32b54 --- /dev/null +++ b/Dynamic-Programming/tests/ClimbingStairs.test.js @@ -0,0 +1,19 @@ +import { climbStairs } from '../ClimbingStairs' + +describe('ClimbingStairs', () => { + it('climbStairs of 0', () => { + expect(climbStairs(0)).toBe(1) + }) + + it('climbStairs of 1', () => { + expect(climbStairs(1)).toBe(1) + }) + + it('climbStairs of 10', () => { + expect(climbStairs(10)).toBe(89) + }) + + it('climbStairs of 15', () => { + expect(climbStairs(15)).toBe(987) + }) +})