Created
May 22, 2015 14:26
-
-
Save kareemgrant/75407d0001da2720728a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Write program that prints out the nth number in a fibonnaci sequence | |
| # fib(n): 0, 1, 1, 2, 3, 5, 8, 13, 21, 34 | |
| # (n): 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 | |
| require 'pry' | |
| require 'minitest/autorun' | |
| require 'minitest/pride' | |
| def fib(n) | |
| return 0 if n == 0 | |
| return 1 if n == 1 | |
| fib(n - 1) + fib(n - 2) | |
| end | |
| class FibTest < MiniTest::Unit::TestCase | |
| def test_n_is_0 | |
| assert_equal 0, fib(0) | |
| end | |
| def test_n_is_1 | |
| assert_equal 1, fib(1) | |
| end | |
| def test_n_is_2 | |
| assert_equal 1, fib(2) | |
| end | |
| def test_n_is_5 | |
| assert_equal 5, fib(5) | |
| end | |
| def test_n_is_6 | |
| assert_equal 8, fib(6) | |
| end | |
| def test_n_is_34 | |
| assert_equal 34, fib(9) | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment