Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import junit.framework.TestCase;
- // Question from https://www.facebook.com/groups/javaharikrishna/permalink/2189431594515722/
- public class ClimbStairsTest extends TestCase {
- private static int waysToClimbStairs(final int numberOfStairs) {
- // Try it yourself.
- // (or see https://pastebin.com/SMzjFmKr )
- }
- public void test() {
- assertUniqueWaysToClimbStairs(1, 0); // There's only one way: You're already there, with zero steps!
- assertUniqueWaysToClimbStairs(1, 1);
- assertUniqueWaysToClimbStairs(2, 2);
- assertUniqueWaysToClimbStairs(3, 3);
- assertUniqueWaysToClimbStairs(5, 4);
- assertUniqueWaysToClimbStairs(8, 5);
- assertUniqueWaysToClimbStairs(13, 6);
- assertUniqueWaysToClimbStairs(21, 7);
- assertUniqueWaysToClimbStairs(34, 8);
- assertUniqueWaysToClimbStairs(55, 9);
- assertUniqueWaysToClimbStairs(89, 10);
- // Turns out, it's the Fibonacci Sequence.
- }
- private static void assertUniqueWaysToClimbStairs(final int expectedWays, final int numberOfStairs) {
- assertEquals("for <" + numberOfStairs + "> stairs;", expectedWays, waysToClimbStairs(numberOfStairs));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement