Решение на Втора задача от Светлин Николов

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

Към профила на Светлин Николов

Резултати

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

Код

class Collection
include Enumerable
attr_accessor :songs
def initialize(songs)
@songs = songs
end
def self.parse(text)
songs = []
text_parse = text.split(%r{\n\s*})
test_parse.each_slice(3).map{|song_array|songs <<Song.new(song_array)}
new(songs)
end
def artists
songs.map { |song| song.artist }
end
def albums
songs.map { |song| song.album }
end
def names
songs.map { |song| song.name }
end
end
class FilterCriteriaObject
attr_accessor :search_string
def initialize(search_string)
@search_string = search_string
end
def &(other)
FilterCriteriaObject.new(self.search_string + ',' + other.search_string)
end
def |(other)
FilterCriteriaObject.new(self.search_string + ';' + other.search_string)
end
def !
FilterCriteriaObject.new('not' + self.search_string)
end
def search_string
@search_string
end
end
class Song
def initialize(song_array)
@name = song_array[0]
@artist = song_array[1]
@album = song_array[2]
end
def name
@name
end
def artist
@artist
end
def album
@album
end
end
class Criteria
def self.name(name)
FilterCriteriaObject.new("name:" + name)
end
def self.artist(artist)
FilterCriteriaObject.new("artist:" + artist)
end
def self.album(album)
FilterCriteriaObject.new("album:" + album)
end
end

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

FFFFFFFFFFF

Failures:

  1) Collection can find all the artists in the collection
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:5: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 find all the names of all songs in the collection
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:17: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 find all the albums in the collection
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:30: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 can be filtered by song name
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:44: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 be filtered by song name
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/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)>'

  6) Collection can be filtered by album
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:54: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 return an empty result
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:59: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 supports a conjuction of filters
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:64: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 supports a disjunction of filters
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/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 supports negation of filters
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:78: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 can be adjoined with another collection
     Failure/Error: let(:collection) { Collection.parse(SONGS) }
     NameError:
       undefined local variable or method `test_parse' for Collection:Class
     # /tmp/d20130203-23049-iajtxl/solution.rb:12:in `parse'
     # /tmp/d20130203-23049-iajtxl/spec.rb:2:in `block (2 levels) in <top (required)>'
     # /tmp/d20130203-23049-iajtxl/spec.rb:83: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.00841 seconds
11 examples, 11 failures

Failed examples:

rspec /tmp/d20130203-23049-iajtxl/spec.rb:4 # Collection can find all the artists in the collection
rspec /tmp/d20130203-23049-iajtxl/spec.rb:16 # Collection can find all the names of all songs in the collection
rspec /tmp/d20130203-23049-iajtxl/spec.rb:29 # Collection can find all the albums in the collection
rspec /tmp/d20130203-23049-iajtxl/spec.rb:43 # Collection can be filtered by song name
rspec /tmp/d20130203-23049-iajtxl/spec.rb:48 # Collection can be filtered by song name
rspec /tmp/d20130203-23049-iajtxl/spec.rb:53 # Collection can be filtered by album
rspec /tmp/d20130203-23049-iajtxl/spec.rb:58 # Collection can return an empty result
rspec /tmp/d20130203-23049-iajtxl/spec.rb:63 # Collection supports a conjuction of filters
rspec /tmp/d20130203-23049-iajtxl/spec.rb:68 # Collection supports a disjunction of filters
rspec /tmp/d20130203-23049-iajtxl/spec.rb:77 # Collection supports negation of filters
rspec /tmp/d20130203-23049-iajtxl/spec.rb:82 # Collection can be adjoined with another collection

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

Светлин обнови решението на 31.10.2012 16:58 (преди около 12 години)

+class Collection
+ include Enumerable
+ attr_accessor :songs
+
+ def initialize(songs)
+ @songs = songs
+ end
+
+ def self.parse(text)
+ songs = []
+ text_parse = text.split(%r{\n\s*})
+ test_parse.each_slice(3).map{|song_array|songs <<Song.new(song_array)}
+ new(songs)
+ end
+
+ def artists
+ songs.map { |song| song.artist }
+ end
+
+ def albums
+ songs.map { |song| song.album }
+ end
+
+ def names
+ songs.map { |song| song.name }
+ end
+
+end
+
+class FilterCriteriaObject
+ attr_accessor :search_string
+ def initialize(search_string)
+ @search_string = search_string
+ end
+
+ def &(other)
+ FilterCriteriaObject.new(self.search_string + ',' + other.search_string)
+ end
+
+ def |(other)
+ FilterCriteriaObject.new(self.search_string + ';' + other.search_string)
+ end
+
+ def !
+ FilterCriteriaObject.new('not' + self.search_string)
+ end
+
+ def search_string
+ @search_string
+ end
+end
+
+class Song
+ def initialize(song_array)
+ @name = song_array[0]
+ @artist = song_array[1]
+ @album = song_array[2]
+ end
+
+ def name
+ @name
+ end
+
+ def artist
+ @artist
+ end
+
+ def album
+ @album
+ end
+end
+
+class Criteria
+ def self.name(name)
+ FilterCriteriaObject.new("name:" + name)
+ end
+
+ def self.artist(artist)
+ FilterCriteriaObject.new("artist:" + artist)
+ end
+
+ def self.album(album)
+ FilterCriteriaObject.new("album:" + album)
+ end
+end