-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathtest.rb
96 lines (74 loc) · 2.26 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
90
91
92
93
94
95
96
require 'minitest/autorun'
require 'pry'
class ListAnalyzer
def initialize
@vowels = ['a', 'e', 'i', 'o', 'u']
end
def number_of_words_starting_with_a_vowel list
count = 0
list.each do |word|
if word.start_with?('a', 'e', 'i', 'o', 'u')
count += 1
end
end
return count
end
def all_words_start_with_vowels? list
# one option:
#number_of_words_starting_with_a_vowel(list) == list.length
list.each do |word|
if !word.start_with?('a', 'e', 'i', 'o', 'u')
return false
end
end
return true
end
def some_word_starts_with_a_vowel? list
# one option:
#number_of_words_starting_with_a_vowel(list) > list.length
list.each do |word|
if word.start_with?('a', 'e', 'i', 'o', 'u')
return true
end
end
return false
end
def number_of_vowels_in_all_words list
number_of_vowels = 0
list.each do |word|
word.each_char do |letter|
#if letter == 'a' || letter == 'e' || letter =='i' || letter == 'o' || letter == 'u'
if @vowels.include?(letter)
number_of_vowels += 1
end
end
end
return number_of_vowels
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
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