Решение на Втора задача от Мария Гроздева

Обратно към всички решения

Към профила на Мария Гроздева

Резултати

  • 0 точки от тестове
  • 0 бонус точки
  • 0 точки общо
  • 0 успешни тест(а)
  • 12 неуспешни тест(а)

Код

class Song
attr_accessor :name, :artist, :genre, :subgenre, :tags
def initialize(name, artist, genre, subgenre, tags)
@name, @artist, @genre, @subgenre = name, artist, genre, subgenre
if tags
@tags = tags.split(",")
@tags << genre.downcase
if subgenre
@tags << subgenre.downcase
end
end
end
end
class Collection
attr_accessor :songs_container , :artist_tags
def parse_song(song_as_string)
collector = []
tags = []
song_as_string.each_line do |new_song|
new_song = new_song.split('.').each { |member| ember.strip!}
if (new_song[2].include? ",")
genre = new_song[2].split(",")[0]
subgenre = new_song[2].split(",")[1].strip!
elem = Song.new(new_song[0],new_song[1], genre, subgenre, new_song[3])
else
elem = Song.new(new_song[0], new_song[1], new_song[2], nil,new_song[3] )
end
collector << elem
end
collector
end
def initialize(songs_as_string, artist_tags)
@artist_tags = artist_tags
@songs_container = parse_song(songs_as_string)
end
def find(criteria)
criteria[value]
end
end

Лог от изпълнението

FFFFFFFFFFFF

Failures:

  1) Collection returns all entries if called without parameters
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x99d6210>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:37:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) Collection can look up songs by artist
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x99d561c>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:41:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) Collection can look up songs by name
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x99d4af0>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:45:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) Collection uses the genre and subgenre as tags
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x99d3fc4>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:100:in `song'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:49:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) Collection can find songs by tag
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x9d0637c>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:53:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) Collection can find songs by multiple tags
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x9d05828>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:57:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) Collection can find songs that don't have a tag
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x9d04cd4>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:61:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) Collection can filter songs by a lambda
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x9d04194>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:65:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) Collection adds the artist tags to the songs
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x9d03668>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:69:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) Collection allows multiple criteria
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x9e52640>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:73:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) Collection allows all criteria
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x9e51ac4>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:96:in `songs'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:82:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) Collection constructs an object for each song
     Failure/Error: let(:collection) { Collection.new input, additional_tags }
     NameError:
       undefined local variable or method `ember' for #<Collection:0x9e50fc0>
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block (2 levels) in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `each'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:24:in `block in parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `each_line'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:23:in `parse_song'
     # /tmp/d20111115-13548-1mxulr4/solution.rb:38:in `initialize'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `new'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:34:in `block (2 levels) in <top (required)>'
     # /tmp/d20111115-13548-1mxulr4/spec.rb:86:in `block (2 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/homework/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.53954 seconds
12 examples, 12 failures

Failed examples:

rspec /tmp/d20111115-13548-1mxulr4/spec.rb:36 # Collection returns all entries if called without parameters
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:40 # Collection can look up songs by artist
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:44 # Collection can look up songs by name
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:48 # Collection uses the genre and subgenre as tags
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:52 # Collection can find songs by tag
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:56 # Collection can find songs by multiple tags
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:60 # Collection can find songs that don't have a tag
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:64 # Collection can filter songs by a lambda
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:68 # Collection adds the artist tags to the songs
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:72 # Collection allows multiple criteria
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:76 # Collection allows all criteria
rspec /tmp/d20111115-13548-1mxulr4/spec.rb:85 # Collection constructs an object for each song

История (1 версия и 0 коментара)

Мария обнови решението на 31.10.2011 16:56 (преди около 13 години)

+class Song
+ attr_accessor :name, :artist, :genre, :subgenre, :tags
+
+ def initialize(name, artist, genre, subgenre, tags)
+ @name, @artist, @genre, @subgenre = name, artist, genre, subgenre
+ if tags
+ @tags = tags.split(",")
+ @tags << genre.downcase
+ if subgenre
+ @tags << subgenre.downcase
+ end
+ end
+ end
+end
+
+
+class Collection
+ attr_accessor :songs_container , :artist_tags
+
+ def parse_song(song_as_string)
+ collector = []
+ tags = []
+ song_as_string.each_line do |new_song|
+ new_song = new_song.split('.').each { |member| ember.strip!}
+ if (new_song[2].include? ",")
+ genre = new_song[2].split(",")[0]
+ subgenre = new_song[2].split(",")[1].strip!
+ elem = Song.new(new_song[0],new_song[1], genre, subgenre, new_song[3])
+ else
+ elem = Song.new(new_song[0], new_song[1], new_song[2], nil,new_song[3] )
+ end
+ collector << elem
+ end
+ collector
+ end
+ def initialize(songs_as_string, artist_tags)
+ @artist_tags = artist_tags
+ @songs_container = parse_song(songs_as_string)
+ end
+
+ def find(criteria)
+ criteria[value]
+ end
+end