diff --git a/spec/part1_spec.rb b/spec/part1_spec.rb index 3d2ab05a..c1471800 100644 --- a/spec/part1_spec.rb +++ b/spec/part1_spec.rb @@ -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 @@ -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 @@ -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 @@ -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