Skip to content

Commit

Permalink
modify the rspec test to verify sum_to_n? as specified in README.md
Browse files Browse the repository at this point in the history
currently sum_to_n? if implemented as specified fails the autograder

autograder output
  #sum_to_n
    should be defined
    returns true when any two elements sum to the second argument [30 points]
    returns false for the single element array [5 points]
    returns false for the empty array [5 points] (FAILED - 7)
  • Loading branch information
bill-auger committed Nov 4, 2015
1 parent e9f6117 commit 7902118
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions spec/part1_spec.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
require 'ruby_intro.rb'

describe 'Ruby intro part 1' do
=begin
describe "#sum" do
it "should be defined" do
expect { sum([1,3,4]) }.not_to raise_error
Expand All @@ -16,7 +17,7 @@
it "works on the empty array [10 points]" , points: 10 do
expect { sum([]) }.not_to raise_error
expect(sum([])).to be_zero
end
end
end
describe "#max_2_sum" do
Expand All @@ -37,16 +38,17 @@
expect(max_2_sum([3])).to eq(3)
end
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]" , points: 30 do
expect(sum_to_n?([1,2,3,4,5], 5)).to be true
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
expect(sum_to_n?([1,2,3,4,5], 5)).to be true # 2 + 3 = 5
expect(sum_to_n?([3,0,5], 5)).to be true # 0 + 5 = 5
expect(sum_to_n?([-1,-2,3,4,5,-8], -3)).to be true # handles negative sum
expect(sum_to_n?([-1,-2,3,4,5,-8], 12)).to be false # 3 + 4 + 5 = 12 (not 3 elements)
expect(sum_to_n?([-1,-2,3,4,6,-8], 12)).to be false # no two elements that sum
end
# for rspec 2.14.1
# it "returns false for the single element array [5 points]" , points: 5 do
Expand All @@ -57,12 +59,14 @@
# sum_to_n?([], 0).should be_false
# sum_to_n?([], 7).should be_false
# end
it "returns false for the single element array [5 points]" , points: 5 do
it "returns false for any single element array [5 points]" , points: 5 do
expect(sum_to_n?([0], 0)).to be false
expect(sum_to_n?([1], 1)).to be false
expect(sum_to_n?([3], 0)).to be false
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]" , points: 5 do
expect(sum_to_n?([], 0)).to be false
it "returns true if the empty array sums to zero [5 points]" , points: 5 do
expect(sum_to_n?([], 0)).to be true
expect(sum_to_n?([], 7)).to be false
end
end
Expand Down

0 comments on commit 7902118

Please sign in to comment.