forked from saasbook/hw-ruby-intro
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpart2_spec.rb
56 lines (52 loc) · 2.33 KB
/
part2_spec.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
require 'ruby_intro.rb'
describe "#hello" do
it "should be defined" do
expect { hello("Testing") }.not_to raise_error()#::NoMethodError)
end
it "The hello method returns the correct string [30 points]" , points: 30 do
expect(hello("Dan").class).to eq(String)
expect(hello("Dan")).to eq('Hello, Dan'), "Incorrect results for input: \"Dan\""
expect(hello("BILL")).to eq('Hello, BILL'), "Incorrect results for input: \"BILL\""
expect(hello("Mr. Ilson")).to eq('Hello, Mr. Ilson'), "Incorrect results for input: \"Mr. Ilson\""
end
end
describe "#starts_with_consonant?" do
it "should be defined" do
expect { starts_with_consonant?("d") }.not_to raise_error()#::NoMethodError)
end
it 'classifies true cases [10 points]' , points: 10 do
expect(starts_with_consonant?('v')).to be_truthy, "'v' is a consonant"
['v', 'vest', 'Veeee', 'crypt'].each do |string|
expect(starts_with_consonant?(string)).to be_truthy, "Incorrect results for input: \"#{string}\""
end
end
it 'classifies false cases [10 points]' , points: 10 do
expect(starts_with_consonant?('a')).to be_falsy, "'a' is not a consonant"
['asdfgh', 'Unix'].each do |string|
expect(starts_with_consonant?(string)).to be_falsy, "Incorrect results for input: \"#{string}\""
end
end
it 'works on the empty string [5 points]' , points: 5 do
expect(starts_with_consonant?('')).to be_falsy
end
it 'works on nonletters [5 points]' , points: 5 do
expect(starts_with_consonant?('#foo')).to be_falsy
end
end
describe "#binary_multiple_of_4?" do
it "should be defined" do
expect { binary_multiple_of_4?("yes") }.not_to raise_error()#::NoMethodError)
end
it "classifies valid binary numbers [30 points]" , points: 30 do
["1010101010100", "0101010101010100", "100", "0"].each do |string|
expect(binary_multiple_of_4?(string)).to be_truthy, "Incorrect results for input: \"#{string}\""
end
["101", "1000000000001"].each do |string|
expect(binary_multiple_of_4?(string)).not_to be_truthy, "Incorrect results for input: \"#{string}\""
end
end
it "rejects invalid binary numbers [10 points]" , points: 10 do
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