Question: Just need help finifhing this code. ---format spec ---color +--format documentation +--color -def sum arr - # YOUR CODE HERE -end - -def max_2_sum arr

Just need help finifhing this code.

---format spec

---color
+--format documentation

+--color

-def sum arr
- # YOUR CODE HERE
-end
-
-def max_2_sum arr
- # YOUR CODE HERE
-end
-
-def sum_to_n? arr, n
- # YOUR CODE HERE
-end
-def hello(name)
- # YOUR CODE HERE
-end
-
-def starts_with_consonant? s
- # YOUR CODE HERE
-end
-
-def binary_multiple_of_4? s
- # YOUR CODE HERE
-end
-class BookInStock
-# YOUR CODE HERE
-end
+# When done, submit this entire file to the autograder.
+
+# Part 1
+
+def sum arr
+ # YOUR CODE HERE
+end
+
+def max_2_sum arr
+ # YOUR CODE HERE
+end
+
+def sum_to_n? arr, n
+ # YOUR CODE HERE
+end
+
+# Part 2
+
+def hello(name)
+ # YOUR CODE HERE
+end
+
+def starts_with_consonant? s
+ # YOUR CODE HERE
+end
+
+def binary_multiple_of_4? s
+ # YOUR CODE HERE
+end
+
+# Part 3
+
+class BookInStock
+# YOUR CODE HERE
+end
@@ -1,69 +1,39 @@
+require 'ruby_intro.rb'
describe 'Ruby intro part 1' do
describe "#sum" do
- it "should be defined" do
- expect { sum([1,3,4]) }.not_to raise_error
- end
-
- it "returns correct sum [20 points]" do
- expect(sum([1,2,3,4,5])).to be_a_kind_of Fixnum
+ it "returns correct sum" do
expect(sum([1,2,3,4,5])).to eq(15)
- expect(sum([1,2,3,4,-5])).to eq(5)
- expect(sum([1,2,3,4,-5,5,-100])).to eq(-90)
end
-
- it "works on the empty array [10 points]" do
- expect { sum([]) }.not_to raise_error
+ it "works on the empty array" do
expect(sum([])).to be_zero
end
end
describe "#max_2_sum" do
- it "should be defined" do
- expect { max_2_sum([1,2,3]) }.not_to raise_error
- end
- it "returns the correct sum [7 points]" do
- expect(max_2_sum([1,2,3,4,5])).to be_a_kind_of Fixnum
+ it "returns the correct sum" do
expect(max_2_sum([1,-2,-3,-4,-5])).to eq(-1)
end
- it 'works even if 2 largest values are the same [3 points]' do
+ it 'works even if 2 largest values are the same' do
expect(max_2_sum([1,2,3,3])).to eq(6)
end
- it "returns zero if array is empty [10 points]" do
+ it "returns zero if array is empty" do
expect(max_2_sum([])).to be_zero
end
- it "returns value of the element if just one element [10 points]" do
+ it "returns value of the element if just one element" do
expect(max_2_sum([3])).to eq(3)
end
end
describe "#sum_to_n" do
- it "should be defined" do
- expect { sum_to_n?([1,2,3],4) }.not_to raise_error
- end
- it "returns true when any two elements sum to the second argument [30 points]" do
- expect(sum_to_n?([1,2,3,4,5], 5)).to be true
+ it "returns true when any two elements sum to the second argument" do
expect(sum_to_n?([3,0,5], 5)).to be true
- expect(sum_to_n?([-1,-2,3,4,5,-8], 12)).to be false
- expect(sum_to_n?([-1,-2,3,4,6,-8], 12)).to be false
end
- #for rspec 3.3.0
- it "returns false for the single element array [5 points]" do
- sum_to_n?([1], 1).should be_falsey
- sum_to_n?([3], 0).should be_falsey
+ it "returns false for the single element array" do
+ expect(sum_to_n?([1], 1)).to be_falsey
end
- it "returns false for the empty array [5 points]" do
- sum_to_n?([], 0).should be_falsey
- sum_to_n?([], 7).should be_falsey
+ it "returns false for the empty array" do
+ expect(sum_to_n?([], 0)).to be_falsey
end
- #for rspec 2.14.1
- # it "returns false for the single element array [5 points]" do
- # expect(sum_to_n?([1], 1)).to be false
- # expect(sum_to_n?([3], 0)).to be false
- # end
- # it "returns false for the empty array [5 points]" do
- # expect(sum_to_n?([], 0)).to be false
- # expect(sum_to_n?([], 7)).to be false
- # end
end
-end
+end

require 'ruby_intro.rb'
describe "#hello" do
it "should be defined" do
expect { hello("Testing") }.not_to raise_error()#::NoMethodError)
@@ -51,4 +52,4 @@
expect(binary_multiple_of_4?('a100')).to be_falsy, "'a100' is not a valid binary number!"
expect(binary_multiple_of_4?('')).to be_falsy, "The empty string is not a valid binary number!"
end
-end
+end

View

1 spec/part3_spec.rb

@@ -1,3 +1,4 @@
+require 'ruby_intro.rb'
describe "BookInStock" do
it "should be defined" do
expect { BookInStock }.not_to raise_error

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!