-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.rb
89 lines (70 loc) · 2.05 KB
/
test.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
require 'minitest/autorun'
require 'pry'
class ListAnalyzer
def starts_with_vowel word
word.start_with?("a", "e", "i", "o", "u")
end
def number_of_words_starting_with_a_vowel words
words_starting_with_vowel = 0
words.each do |word|
if starts_with_vowel word
words_starting_with_vowel += 1
end
end
words_starting_with_vowel
end
def all_words_start_with_vowels? words
words.each do |word|
unless starts_with_vowel word
false
end
end
end
def number_of_vowels_in_all_words words
number_of_vowels = 0
words.each do |word|
letters = word.split("")
letters.each do |letter|
if starts_with_vowel letter
number_of_vowels += 1
end
end
end
number_of_vowels
end
def some_word_starts_with_a_vowel? words
words.each do |word|
if starts_with_vowel word
return true
end
end
return false
end
end
class ListTest < MiniTest::Test
def test_it_can_count_vowels
produce = ["apricot", "beet", "clementine", "date", "elderberry"]
lister = ListAnalyzer.new
assert_equal 2, lister.number_of_words_starting_with_a_vowel(produce)
end
def test_it_can_check_a_whole_list_for_matches
mostly_vowels = ["iceberg", "ugli", "endive", "plum", "olive"]
lister = ListAnalyzer.new
binding.pry
refute lister.all_words_start_with_vowels?(mostly_vowels)
mostly_vowels.delete "plum"
assert lister.all_words_start_with_vowels?(mostly_vowels)
end
def test_it_can_check_for_a_single_example
mostly_consonants = ["pear", "quince", "aubergine", "zucchini", "pineapple"]
lister = ListAnalyzer.new
assert lister.some_word_starts_with_a_vowel?(mostly_consonants)
mostly_consonants.delete "aubergine"
refute lister.some_word_starts_with_a_vowel?(mostly_consonants)
end
def test_it_can_count_all_vowels
produce = ["apricot", "beet", "clementine", "date", "elderberry"]
lister = ListAnalyzer.new
assert_equal 14, lister.number_of_vowels_in_all_words(produce)
end
end