-
Notifications
You must be signed in to change notification settings - Fork 234
/
find_first_one_test.rb
151 lines (122 loc) · 2.9 KB
/
find_first_one_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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
gem 'minitest'
require 'minitest/autorun'
require 'minitest/pride'
# You get the first test for free... it's already passing.
class FindFirstWeirdThingTest < Minitest::Test
class Thing
def initialize(adjective)
@adjective = adjective
end
def weird?
@adjective == 'weird'
end
end
def test_first_weird_thing
thing1 = Thing.new('odd')
thing2 = Thing.new('cool')
thing3 = Thing.new('weird')
thing4 = Thing.new('fun')
thing5 = Thing.new('weird')
things = [thing1, thing2, thing3, thing4, thing5]
found = nil
things.each do |thing|
if thing.weird?
found = thing
break
end
end
assert_equal thing3, found
end
end
# This one is missing the block inside the loop.
class FindFirstPinkUnicornTest < Minitest::Test
class Unicorn
def initialize(color)
@color = color
end
def pink?
@color == 'pink'
end
end
def test_first_pink_unicorn
skip
unicorn1 = Unicorn.new('white')
unicorn2 = Unicorn.new('sparkly')
unicorn3 = Unicorn.new('purple')
unicorn4 = Unicorn.new('pink')
unicorn5 = Unicorn.new('pink')
unicorns = [unicorn1, unicorn2, unicorn3, unicorn4, unicorn5]
found = nil
unicorns.each do |unicorn|
# write code here
end
assert_equal unicorn4, found
end
end
# This one is missing the entire loop
class FindFirstRovingGnomeTest < Minitest::Test
class Gnome
def initialize(type)
@type = type
end
def roving?
@type == 'roving'
end
end
def test_first_roving_gnome
skip
gnome1 = Gnome.new('forest')
gnome2 = Gnome.new('roving')
gnome3 = Gnome.new('snorkeling')
gnome4 = Gnome.new('evil')
gnome5 = Gnome.new('roving')
gnomes = [gnome1, gnome2, gnome3, gnome4, gnome5]
found = nil
# write code here
assert_equal gnome2, found
end
end
# You're on your own on this one.
class FindFirstGiantSquidTest < Minitest::Test
class Squid
def initialize(size)
@size = size
end
def giant?
@size == 'giant'
end
end
def test_first_giant_squid
skip
squid1 = Squid.new('tiny')
squid2 = Squid.new('inky')
squid3 = Squid.new('giant')
squid4 = Squid.new('deep sea')
squid5 = Squid.new('giant')
squiddies = [squid1, squid2, squid3, squid4, squid5]
# write code here
assert_equal squid3, found
end
end
class FindFirstWeirdThingUsingFindTest < Minitest::Test
class Thing
def initialize(adjective)
@adjective = adjective
end
def weird?
@adjective == 'weird'
end
end
def test_first_weird_thing_using_find
thing1 = Thing.new('odd')
thing2 = Thing.new('cool')
thing3 = Thing.new('weird')
thing4 = Thing.new('fun')
thing5 = Thing.new('weird')
things = [thing1, thing2, thing3, thing4, thing5]
found = things.find do |thing|
thing.weird?
end
assert_equal thing3, found
end
end