forked from rabajaj0509/Ruby-concepts-step-by-step
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3a6aaa7
commit 2d9cd7a
Showing
2 changed files
with
36 additions
and
0 deletions.
There are no files selected for viewing
7 changes: 7 additions & 0 deletions
7
Test Driven Development in Ruby/fibonacci sequece/fibonacci.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class Fibonacci | ||
def self.of(n) | ||
return 0 if n == 0 | ||
return 1 if n <= 2 | ||
return of(n - 1) + of(n - 2) | ||
end | ||
end |
29 changes: 29 additions & 0 deletions
29
Test Driven Development in Ruby/fibonacci sequece/test_fibonacci.rb
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
require 'minitest/autorun' | ||
require_relative 'fibonacci' | ||
|
||
class TestFibonacci < Minitest::Test | ||
def test_fibonacci_of_zero_is_zero | ||
result = Fibonacci.of(0) | ||
assert_equal 0, result | ||
end | ||
|
||
def test_fibonacci_of_one_is_one | ||
result = Fibonacci.of(1) | ||
assert_equal 1, result | ||
end | ||
|
||
def test_fibonacci_of_two_is_one | ||
result = Fibonacci.of(2) | ||
assert_equal 1, result | ||
end | ||
|
||
def test_fibonacci_of_three_is_two | ||
result = Fibonacci.of(3) | ||
assert_equal 2, result | ||
end | ||
|
||
def test_fibonacci_of_ten_is_fifty_five | ||
result = Fibonacci.of(10) | ||
assert_equal 55, result | ||
end | ||
end |