|
1 |
| -require 'ruby_intro.rb' |
| 1 | +# frozen_string_literal: true |
2 | 2 |
|
3 |
| -describe 'Ruby intro part 1' do |
| 3 | +require_relative '../lib/ruby_intro' |
4 | 4 |
|
5 |
| - describe "#sum" do |
6 |
| - it "should be defined" do |
7 |
| - expect { sum([1,3,4]) }.not_to raise_error |
| 5 | +describe 'Ruby intro part 1' do |
| 6 | + describe '#sum' do |
| 7 | + it 'should be defined' do |
| 8 | + expect { sum([1, 3, 4]) }.not_to raise_error |
8 | 9 | end
|
9 | 10 |
|
10 |
| - it "returns correct sum [20 points]" , points: 20 do |
11 |
| - expect(sum([1,2,3,4,5])).to be_a_kind_of Fixnum |
12 |
| - expect(sum([1,2,3,4,5])).to eq(15) |
13 |
| - expect(sum([1,2,3,4,-5])).to eq(5) |
14 |
| - expect(sum([1,2,3,4,-5,5,-100])).to eq(-90) |
| 11 | + it 'returns correct sum [20 points]', points: 20 do |
| 12 | + expect(sum([1, 2, 3, 4, 5])).to be_a_kind_of Fixnum |
| 13 | + expect(sum([1, 2, 3, 4, 5])).to eq(15) |
| 14 | + expect(sum([1, 2, 3, 4, -5])).to eq(5) |
| 15 | + expect(sum([1, 2, 3, 4, -5, 5, -100])).to eq(-90) |
15 | 16 | end
|
16 | 17 |
|
17 |
| - it "works on the empty array [10 points]" , points: 10 do |
| 18 | + it 'works on the empty array [10 points]', points: 10 do |
18 | 19 | expect { sum([]) }.not_to raise_error
|
19 | 20 | expect(sum([])).to be_zero
|
20 | 21 | end
|
21 | 22 | end
|
22 | 23 |
|
23 |
| - describe "#max_2_sum" do |
24 |
| - it "should be defined" do |
25 |
| - expect { max_2_sum([1,2,3]) }.not_to raise_error |
| 24 | + describe '#max_2_sum' do |
| 25 | + it 'should be defined' do |
| 26 | + expect { max_2_sum([1, 2, 3]) }.not_to raise_error |
26 | 27 | end
|
27 |
| - it "returns the correct sum [7 points]" , points: 7 do |
28 |
| - expect(max_2_sum([1,2,3,4,5])).to be_a_kind_of Fixnum |
29 |
| - expect(max_2_sum([1,-2,-3,-4,-5])).to eq(-1) |
| 28 | + it 'returns the correct sum [7 points]', points: 7 do |
| 29 | + expect(max_2_sum([1, 2, 3, 4, 5])).to be_a_kind_of Fixnum |
| 30 | + expect(max_2_sum([1, -2, -3, -4, -5])).to eq(-1) |
30 | 31 | end
|
31 |
| - it 'works even if 2 largest values are the same [3 points]' , points: 3 do |
32 |
| - expect(max_2_sum([1,2,3,3])).to eq(6) |
| 32 | + it 'works even if 2 largest values are the same [3 points]', points: 3 do |
| 33 | + expect(max_2_sum([1, 2, 3, 3])).to eq(6) |
33 | 34 | end
|
34 |
| - it "returns zero if array is empty [10 points]" , points: 10 do |
| 35 | + it 'returns zero if array is empty [10 points]', points: 10 do |
35 | 36 | expect(max_2_sum([])).to be_zero
|
36 | 37 | end
|
37 |
| - it "returns value of the element if just one element [10 points]" , points: 10 do |
| 38 | + it 'returns value of the element if just one element [10 points]', points: 10 do |
38 | 39 | expect(max_2_sum([3])).to eq(3)
|
39 | 40 | end
|
40 | 41 | end
|
41 | 42 |
|
42 |
| - describe "#sum_to_n" do |
43 |
| - it "should be defined" do |
44 |
| - expect { sum_to_n?([1,2,3],4) }.not_to raise_error |
| 43 | + describe '#sum_to_n' do |
| 44 | + it 'should be defined' do |
| 45 | + expect { sum_to_n?([1, 2, 3], 4) }.not_to raise_error |
45 | 46 | end
|
46 |
| - it "returns true when any two elements sum to the second argument [30 points]" , points: 30 do |
47 |
| - expect(sum_to_n?([1,2,3,4,5], 5)).to be true # 2 + 3 = 5 |
48 |
| - expect(sum_to_n?([3,0,5], 5)).to be true # 0 + 5 = 5 |
49 |
| - expect(sum_to_n?([-1,-2,3,4,5,-8], -3)).to be true # handles negative sum |
50 |
| - expect(sum_to_n?([-1,-2,3,4,5,-8], 12)).to be false # 3 + 4 + 5 = 12 (not 3 elements) |
51 |
| - expect(sum_to_n?([-1,-2,3,4,6,-8], 12)).to be false # no two elements that sum |
| 47 | + it 'returns true when any two elements sum to the second argument [30 points]', points: 30 do |
| 48 | + expect(sum_to_n?([1, 2, 3, 4, 5], 5)).to be true # 2 + 3 = 5 |
| 49 | + expect(sum_to_n?([3, 0, 5], 5)).to be true # 0 + 5 = 5 |
| 50 | + expect(sum_to_n?([-1, -2, 3, 4, 5, -8], -3)).to be true # handles negative sum |
| 51 | + expect(sum_to_n?([-1, -2, 3, 4, 5, -8], 12)).to be false # 3 + 4 + 5 = 12 (not 3 elements) |
| 52 | + expect(sum_to_n?([-1, -2, 3, 4, 6, -8], 12)).to be false # no two elements that sum |
52 | 53 | end
|
53 | 54 | # for rspec 2.14.1
|
54 | 55 | # it "returns false for the single element array [5 points]" , points: 5 do
|
|
59 | 60 | # sum_to_n?([], 0).should be_false
|
60 | 61 | # sum_to_n?([], 7).should be_false
|
61 | 62 | # end
|
62 |
| - it "returns false for any single element array [5 points]" , points: 5 do |
| 63 | + it 'returns false for any single element array [5 points]', points: 5 do |
63 | 64 | expect(sum_to_n?([0], 0)).to be false
|
64 | 65 | expect(sum_to_n?([1], 1)).to be false
|
65 | 66 | expect(sum_to_n?([-1], -1)).to be false
|
66 | 67 | expect(sum_to_n?([-3], 0)).to be false
|
67 | 68 | end
|
68 |
| - it "returns false for an empty array [5 points]" , points: 5 do |
| 69 | + it 'returns false for an empty array [5 points]', points: 5 do |
69 | 70 | expect(sum_to_n?([], 0)).to be false
|
70 | 71 | expect(sum_to_n?([], 7)).to be false
|
71 | 72 | end
|
|
0 commit comments