diff --git a/recursion/1_factorial/.rspec b/recursion/1_factorial/.rspec new file mode 100644 index 0000000000..c99d2e7396 --- /dev/null +++ b/recursion/1_factorial/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/recursion/1_factorial/exercises/factorial.rb b/recursion/1_factorial/exercises/factorial.rb new file mode 100644 index 0000000000..17b5702df8 --- /dev/null +++ b/recursion/1_factorial/exercises/factorial.rb @@ -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 diff --git a/recursion/1_factorial/spec/factorial_spec.rb b/recursion/1_factorial/spec/factorial_spec.rb new file mode 100644 index 0000000000..d357b930ba --- /dev/null +++ b/recursion/1_factorial/spec/factorial_spec.rb @@ -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 diff --git a/recursion/1_factorial/spec/spec_helper.rb b/recursion/1_factorial/spec/spec_helper.rb new file mode 100644 index 0000000000..71b90cde10 --- /dev/null +++ b/recursion/1_factorial/spec/spec_helper.rb @@ -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 diff --git a/solutions/recursion/1_factorial/.rspec b/solutions/recursion/1_factorial/.rspec new file mode 100644 index 0000000000..c99d2e7396 --- /dev/null +++ b/solutions/recursion/1_factorial/.rspec @@ -0,0 +1 @@ +--require spec_helper diff --git a/solutions/recursion/1_factorial/exercises/factorial.rb b/solutions/recursion/1_factorial/exercises/factorial.rb new file mode 100644 index 0000000000..0e87897203 --- /dev/null +++ b/solutions/recursion/1_factorial/exercises/factorial.rb @@ -0,0 +1,7 @@ +def factorial(num) + # write a recursive method for calculating the [factorial](https://simple.wikipedia.org/wiki/Factorial) of a number + return if num.negative? + return 1 if num <= 1 + + num * factorial(num - 1) +end diff --git a/solutions/recursion/1_factorial/spec/factorial_spec.rb b/solutions/recursion/1_factorial/spec/factorial_spec.rb new file mode 100644 index 0000000000..f89be53f12 --- /dev/null +++ b/solutions/recursion/1_factorial/spec/factorial_spec.rb @@ -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 + + it "returns 24 when passed the number 4" do + expect(factorial(4)).to eq(24) + end + + it "returns 3628800 when passed the number 10" do + expect(factorial(10)).to eq(3628800) + end + + it "returns 1 when passed the number 0" do + expect(factorial(0)).to eq(1) + end + + it "returns nil when passed a negative number" do + expect(factorial(-5)).to be_nil + end + end +end diff --git a/solutions/recursion/1_factorial/spec/spec_helper.rb b/solutions/recursion/1_factorial/spec/spec_helper.rb new file mode 100644 index 0000000000..71b90cde10 --- /dev/null +++ b/solutions/recursion/1_factorial/spec/spec_helper.rb @@ -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