Advertisement
JeffGrigg

number of ways to climb stairs

Aug 17th, 2019
999
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 5 1.21 KB | None | 0 0
  1. import junit.framework.TestCase;
  2.  
  3. // Question from https://www.facebook.com/groups/javaharikrishna/permalink/2189431594515722/
  4.  
  5. public class ClimbStairsTest extends TestCase {
  6.  
  7.     private static int waysToClimbStairs(final int numberOfStairs) {
  8.         // Try it yourself.
  9.         // (or see https://pastebin.com/SMzjFmKr )
  10.     }
  11.  
  12.     public void test() {
  13.         assertUniqueWaysToClimbStairs(1, 0);    // There's only one way: You're already there, with zero steps!
  14.         assertUniqueWaysToClimbStairs(1, 1);
  15.         assertUniqueWaysToClimbStairs(2, 2);
  16.         assertUniqueWaysToClimbStairs(3, 3);
  17.         assertUniqueWaysToClimbStairs(5, 4);
  18.         assertUniqueWaysToClimbStairs(8, 5);
  19.         assertUniqueWaysToClimbStairs(13, 6);
  20.         assertUniqueWaysToClimbStairs(21, 7);
  21.         assertUniqueWaysToClimbStairs(34, 8);
  22.         assertUniqueWaysToClimbStairs(55, 9);
  23.         assertUniqueWaysToClimbStairs(89, 10);
  24.         // Turns out, it's the Fibonacci Sequence.
  25.     }
  26.  
  27.     private static void assertUniqueWaysToClimbStairs(final int expectedWays, final int numberOfStairs) {
  28.         assertEquals("for <" + numberOfStairs + "> stairs;", expectedWays, waysToClimbStairs(numberOfStairs));
  29.     }
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement