Выполняю задание kindergarten_garden на exercism
Пишу такой код
class Garden
STUDENTS = [:alice, :bob, :charlie, :david,
:eve, :fred, :ginny, :harriet,
:ileana, :joseph, :kincaid, :larry]
PLANTS = {"V" => :violets,
"C" => :clover,
"G" => :grass,
"R" => :radishes}
def initialize(diagram, students = STUDENTS)
students = students.map {|s| s.downcase.to_sym }.sort
row1, row2 = diagram
.lines
.map(&:chomp)
.map(&:each_char)
row1, row2 = row1.each_slice(2), row2.each_slice(2)
row1.zip(row2).each_with_index do |plants, idx|
self.class.send(:define_method,
students[idx],
-> { plants.flatten.map {|p| PLANTS[p] } })
end
end
end
на тесте
class TwoGardensDifferentStudents < Minitest::Test
def diagram
"VCRRGVRG\nRVGCCGCV"
end
def garden_1
@garden_1 ||= Garden.new(diagram, %w(Alice Bob Charlie Dan))
end
def garden_2
@garden_2 ||= Garden.new(diagram, %w(Bob Charlie Dan Erin))
end
def test_bob_and_charlie_per_garden
assert_equal [:radishes, :radishes, :grass, :clover], garden_1.bob
assert_equal [:violets, :clover, :radishes, :violets], garden_2.bob
assert_equal [:grass, :violets, :clover, :grass], garden_1.charlie
assert_equal [:radishes, :radishes, :grass, :clover], garden_2.charlie
end
end
вылетает с ошибкой
1) Failure:
TwoGardensDifferentStudents#test_bob_and_charlie_per_garden [kindergarten_garden_test.rb:128]:
--- expected
+++ actual
@@ -1 +1 @@
-[:grass, :violets, :clover, :grass]
+[:radishes, :radishes, :grass, :clover]
хотя вывод значения для assert на консоль выдает корректное значение.
Никак не могу понять почему.