Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Recursion Exercises: Add new factorial exercise #98

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions recursion/1_factorial/.rspec
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
--require spec_helper
3 changes: 3 additions & 0 deletions recursion/1_factorial/exercises/factorial.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
def factorial(num)
# write a recursive method for calculating the [factorial](https://simple.wikipedia.org/wiki/Factorial) of a number
end
26 changes: 26 additions & 0 deletions recursion/1_factorial/spec/factorial_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require "spec_helper"
require_relative "../exercises/factorial"

RSpec.describe "Factorial" do
describe "factorial exercise" do
it "returns 1 when passed the number 1" do
expect(factorial(1)).to eq(1)
end

xit "returns 24 when passed the number 4" do
expect(factorial(4)).to eq(24)
end

xit "returns 3628800 when passed the number 10" do
expect(factorial(10)).to eq(3628800)
end

xit "returns 1 when passed the number 0" do
expect(factorial(0)).to eq(1)
end

xit "returns nil when passed a negative number" do
expect(factorial(-5)).to be_nil
end
end
end
18 changes: 18 additions & 0 deletions recursion/1_factorial/spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
RSpec.configure do |config|
config.expect_with :rspec do |expectations|
expectations.include_chain_clauses_in_custom_matcher_descriptions = true
end

config.mock_with :rspec do |mocks|
mocks.verify_partial_doubles = true
end

config.shared_context_metadata_behavior = :apply_to_host_groups
end

module FormatterOverrides
def dump_pending(_)
end
end

RSpec::Core::Formatters::DocumentationFormatter.prepend FormatterOverrides