Skip to content

Instantly share code, notes, and snippets.

@jacoyutorius
Created May 13, 2015 11:14
Show Gist options
  • Select an option

  • Save jacoyutorius/44fc7e4c9deb329b816c to your computer and use it in GitHub Desktop.

Select an option

Save jacoyutorius/44fc7e4c9deb329b816c to your computer and use it in GitHub Desktop.
Hamamatsu.rb#52 FibonacciNumber
class FibonacciNumber
def get x
case x
when 0, 1
return 1
else
get(x - 2) + get(x - 1)
end
end
end
if __FILE__ == $0
p FibonacciNumber.new.get(10)
p FibonacciNumber.new.get(50)
end
require "spec_helper"
require "fib"
describe "FibonacciNumber spec" do
it "0の場合、1" do
expect(FibonacciNumber.new.get(1)).to eq 1
end
it "1の場合、1" do
expect(FibonacciNumber.new.get(1)).to eq 1
end
it "2の場合、2" do
expect(FibonacciNumber.new.get(2)).to eq 2
end
it "3の場合、3" do
expect(FibonacciNumber.new.get(3)).to eq 3
end
it "5の場合、5" do
expect(FibonacciNumber.new.get(5)).to eq 8
end
it "8の場合、21" do
expect(FibonacciNumber.new.get(8)).to eq 34
end
it "9の場合、55" do
expect(FibonacciNumber.new.get(9)).to eq 55
end
it "10の場合、55" do
expect(FibonacciNumber.new.get(10)).to eq 89
end
# it "99の場合、" do
# expect(FibonacciNumber.new.get(10)).to eq 55
# end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment