Skip to content

Commit e5dcae0

Browse files
committed
Setup ruby version to 2.5.0
Rubocop offenses were fixed.
1 parent 232e3df commit e5dcae0

File tree

7 files changed

+107
-71
lines changed

7 files changed

+107
-71
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
.idea

.ruby-version

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2.5.0

Gemfile

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
source 'https://rubygems.org'
2-
ruby '2.3.0'
2+
ruby '2.5.0'
33

4-
gem 'rspec'
4+
gem 'rspec', '~> 3.7'

Gemfile.lock

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
GEM
2+
remote: https://rubygems.org/
3+
specs:
4+
diff-lcs (1.3)
5+
rspec (3.7.0)
6+
rspec-core (~> 3.7.0)
7+
rspec-expectations (~> 3.7.0)
8+
rspec-mocks (~> 3.7.0)
9+
rspec-core (3.7.1)
10+
rspec-support (~> 3.7.0)
11+
rspec-expectations (3.7.0)
12+
diff-lcs (>= 1.2.0, < 2.0)
13+
rspec-support (~> 3.7.0)
14+
rspec-mocks (3.7.0)
15+
diff-lcs (>= 1.2.0, < 2.0)
16+
rspec-support (~> 3.7.0)
17+
rspec-support (3.7.1)
18+
19+
PLATFORMS
20+
ruby
21+
22+
DEPENDENCIES
23+
rspec (~> 3.7)
24+
25+
RUBY VERSION
26+
ruby 2.5.0p0
27+
28+
BUNDLED WITH
29+
1.16.1

spec/part1_spec.rb

+33-32
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,55 @@
1-
require 'ruby_intro.rb'
1+
# frozen_string_literal: true
22

3-
describe 'Ruby intro part 1' do
3+
require_relative '../lib/ruby_intro'
44

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
89
end
910

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)
1516
end
1617

17-
it "works on the empty array [10 points]" , points: 10 do
18+
it 'works on the empty array [10 points]', points: 10 do
1819
expect { sum([]) }.not_to raise_error
1920
expect(sum([])).to be_zero
2021
end
2122
end
2223

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
2627
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)
3031
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)
3334
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
3536
expect(max_2_sum([])).to be_zero
3637
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
3839
expect(max_2_sum([3])).to eq(3)
3940
end
4041
end
4142

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
4546
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
5253
end
5354
# for rspec 2.14.1
5455
# it "returns false for the single element array [5 points]" , points: 5 do
@@ -59,13 +60,13 @@
5960
# sum_to_n?([], 0).should be_false
6061
# sum_to_n?([], 7).should be_false
6162
# 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
6364
expect(sum_to_n?([0], 0)).to be false
6465
expect(sum_to_n?([1], 1)).to be false
6566
expect(sum_to_n?([-1], -1)).to be false
6667
expect(sum_to_n?([-3], 0)).to be false
6768
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
6970
expect(sum_to_n?([], 0)).to be false
7071
expect(sum_to_n?([], 7)).to be false
7172
end

spec/part2_spec.rb

+24-22
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
1-
require 'ruby_intro.rb'
1+
# frozen_string_literal: true
22

3-
describe "#hello" do
4-
it "should be defined" do
5-
expect { hello("Testing") }.not_to raise_error()#::NoMethodError)
3+
require_relative '../lib/ruby_intro'
4+
5+
describe '#hello' do
6+
it 'should be defined' do
7+
expect { hello('Testing') }.not_to raise_error#::NoMethodError)
68
end
79

8-
it "The hello method returns the correct string [30 points]" , points: 30 do
9-
expect(hello("Dan").class).to eq(String)
10-
expect(hello("Dan")).to eq('Hello, Dan'), "Incorrect results for input: \"Dan\""
11-
expect(hello("BILL")).to eq('Hello, BILL'), "Incorrect results for input: \"BILL\""
12-
expect(hello("Mr. Ilson")).to eq('Hello, Mr. Ilson'), "Incorrect results for input: \"Mr. Ilson\""
10+
it 'The hello method returns the correct string [30 points]', points: 30 do
11+
expect(hello('Dan').class).to eq(String)
12+
expect(hello('Dan')).to eq('Hello, Dan'), 'Incorrect results for input: "Dan"'
13+
expect(hello('BILL')).to eq('Hello, BILL'), 'Incorrect results for input: "BILL"'
14+
expect(hello('Mr. Ilson')).to eq('Hello, Mr. Ilson'), 'Incorrect results for input: "Mr. Ilson"'
1315
end
1416
end
1517

16-
describe "#starts_with_consonant?" do
17-
it "should be defined" do
18-
expect { starts_with_consonant?("d") }.not_to raise_error()#::NoMethodError)
18+
describe '#starts_with_consonant?' do
19+
it 'should be defined' do
20+
expect { starts_with_consonant?('d') }.not_to raise_error#::NoMethodError)
1921
end
2022
it 'classifies true cases [10 points]' , points: 10 do
2123
expect(starts_with_consonant?('v')).to be_truthy, "'v' is a consonant"
22-
['v', 'vest', 'Veeee', 'crypt'].each do |string|
24+
%w[v vest Veeee crypt].each do |string|
2325
expect(starts_with_consonant?(string)).to be_truthy, "Incorrect results for input: \"#{string}\""
2426
end
2527
end
2628
it 'classifies false cases [10 points]' , points: 10 do
2729
expect(starts_with_consonant?('a')).to be_falsy, "'a' is not a consonant"
28-
['asdfgh', 'Unix'].each do |string|
30+
%w[asdfgh Unix].each do |string|
2931
expect(starts_with_consonant?(string)).to be_falsy, "Incorrect results for input: \"#{string}\""
3032
end
3133
end
@@ -37,20 +39,20 @@
3739
end
3840
end
3941

40-
describe "#binary_multiple_of_4?" do
41-
it "should be defined" do
42-
expect { binary_multiple_of_4?("yes") }.not_to raise_error()#::NoMethodError)
42+
describe '#binary_multiple_of_4?' do
43+
it 'should be defined' do
44+
expect { binary_multiple_of_4?('yes') }.not_to raise_error#::NoMethodError)
4345
end
44-
it "classifies valid binary numbers [30 points]" , points: 30 do
45-
["1010101010100", "0101010101010100", "100", "0"].each do |string|
46+
it 'classifies valid binary numbers [30 points]' , points: 30 do
47+
%w[1010101010100 0101010101010100 100 0].each do |string|
4648
expect(binary_multiple_of_4?(string)).to be_truthy, "Incorrect results for input: \"#{string}\""
4749
end
48-
["101", "1000000000001"].each do |string|
50+
%w[101 1000000000001].each do |string|
4951
expect(binary_multiple_of_4?(string)).not_to be_truthy, "Incorrect results for input: \"#{string}\""
5052
end
5153
end
52-
it "rejects invalid binary numbers [10 points]" , points: 10 do
54+
it 'rejects invalid binary numbers [10 points]' , points: 10 do
5355
expect(binary_multiple_of_4?('a100')).to be_falsy, "'a100' is not a valid binary number!"
54-
expect(binary_multiple_of_4?('')).to be_falsy, "The empty string is not a valid binary number!"
56+
expect(binary_multiple_of_4?('')).to be_falsy, 'The empty string is not a valid binary number!'
5557
end
5658
end

spec/part3_spec.rb

+17-15
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
1-
require 'ruby_intro.rb'
1+
# frozen_string_literal: true
22

3-
describe "BookInStock" do
4-
it "should be defined" do
3+
require_relative '../lib/ruby_intro'
4+
5+
describe 'BookInStock' do
6+
it 'should be defined' do
57
expect { BookInStock }.not_to raise_error
68
end
79

810
describe 'getters and setters' do
911
before(:each) { @book = BookInStock.new('isbn1', 33.8) }
10-
it 'should set ISBN [10 points]' , points: 10 do
12+
it 'should set ISBN [10 points]', points: 10 do
1113
expect(@book.isbn).to eq('isbn1')
1214
end
13-
it 'should set price [10 points]' , points: 10 do
15+
it 'should set price [10 points]', points: 10 do
1416
expect(@book.price).to eq(33.8)
1517
end
16-
it 'should be able to change ISBN [10 points]' , points: 10 do
18+
it 'should be able to change ISBN [10 points]', points: 10 do
1719
@book.isbn = 'isbn2'
1820
expect(@book.isbn).to eq('isbn2')
1921
end
20-
it 'should be able to change price [10 points]' , points: 10 do
22+
it 'should be able to change price [10 points]', points: 10 do
2123
@book.price = 300.0
2224
expect(@book.price).to eq(300.0)
2325
end
2426
end
2527
describe 'constructor' do
26-
it 'should reject invalid ISBN number [10 points]' , points: 10 do
28+
it 'should reject invalid ISBN number [10 points]', points: 10 do
2729
expect { BookInStock.new('', 25.00) }.to raise_error(ArgumentError)
2830
end
29-
it 'should reject zero price [10 points]' , points: 10 do
31+
it 'should reject zero price [10 points]', points: 10 do
3032
expect { BookInStock.new('isbn1', 0) }.to raise_error(ArgumentError)
3133
end
32-
it 'should reject negative price [10 points]' , points: 10 do
34+
it 'should reject negative price [10 points]', points: 10 do
3335
expect { BookInStock.new('isbn1', -5.0) }.to raise_error(ArgumentError)
3436
end
3537
end
36-
describe "#price_as_string" do
37-
it "should be defined" do
38+
describe '#price_as_string' do
39+
it 'should be defined' do
3840
expect(BookInStock.new('isbn1', 10)).to respond_to(:price_as_string)
3941
end
40-
it 'should display 33.95 as "$33.95" [10 points]' , points: 10 do
42+
it 'should display 33.95 as "$33.95" [10 points]', points: 10 do
4143
expect(BookInStock.new('isbn11', 33.95).price_as_string).to eq('$33.95')
4244
end
43-
it "should display 1.1 as $1.10 [10 points]" , points: 10 do
45+
it 'should display 1.1 as $1.10 [10 points]', points: 10 do
4446
expect(BookInStock.new('isbn11', 1.1).price_as_string).to eq('$1.10')
4547
end
46-
it "should display 20 as $20.00 [10 points]" , points: 10 do
48+
it 'should display 20 as $20.00 [10 points]', points: 10 do
4749
expect(BookInStock.new('isbn11', 20).price_as_string).to eq('$20.00')
4850
end
4951
end

0 commit comments

Comments
 (0)