Решение на Втора задача от Ангел Цанев

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

Към профила на Ангел Цанев

Резултати

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

Код

class Task
attr_reader :status, :description, :status, :tags
def initialize(arguments)
@status = arguments[0].downcase.to_sym
@description = arguments[1]
@priority = arguments[2].downcase.to_sym
@tags = (arguments[3] or "").split(', ')
end
end
module CriteriaOperations
def |(other)
#
end
def &(other)
#
end
def !(expresion)
#
end
end
class Criteria
include CriteriaOperations
attr_accessor :priority, :status, :tags
def initialize()
@priority = []
@status = []
@tags = []
end
def priority(priority_symbol)
@priority << priority_symbol
end
def status(status_symbol)
@status << status_symbol
end
def tags(tags_array)
@tags << tags_array
end
end
module TodoListStatistics
def tasks_todo
our_task_list.select { |task| task.status == :todo } .size
end
def tasks_in_progress
our_task_list.select { |task| task.status == :current } .size
end
def tasks_completed
our_task_list.select { |task| task.status == :done } .size
end
def completed?
our_task_list.all? { |task| task.status == :done }
end
end
class TodoList
include Enumerable
include TodoListStatistics
attr_reader :our_task_list
@our_task_list = []
def initialize(arguments)
@our_task_list = arguments
end
def self.parse(text)
task_list = []
text.split(/\n\t*/).each_with_index do |line|
task_list << Task.new(line.split(/ *\| */))
end
TodoList.new(task_list)
end
def each
@our_task_list.each{ |task| yield task }
end
end

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

FFFFFFFFFFFFFFFFF.F..F

Failures:

  1) TodoList filters tasks by status
     Failure/Error: todo_list.filter(Criteria.status :done).map(&:description).should =~ [
     NoMethodError:
       undefined method `status' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:19:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  2) TodoList filters tasks by priority
     Failure/Error: todo_list.filter(Criteria.priority :high).map(&:description).should =~ [
     NoMethodError:
       undefined method `priority' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:26:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  3) TodoList filters tasks by tag
     Failure/Error: todo_list.filter(Criteria.tags %w[food]).map(&:description).should =~ ['Eat spaghetti.']
     NoMethodError:
       undefined method `tags' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:36:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  4) TodoList filters tasks by multiple tags
     Failure/Error: todo_list.filter(Criteria.tags %w[development ruby]).map(&:description).should =~ [
     NoMethodError:
       undefined method `tags' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:40:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  5) TodoList filtering by multiple tags matches only tasks with all the tags
     Failure/Error: todo_list.filter(Criteria.tags %w[development FMI]).map(&:description).should =~ ['Do the 5th Ruby challenge.']
     NoMethodError:
       undefined method `tags' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:47:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  6) TodoList supports a conjuction of filters
     Failure/Error: filtered = todo_list.filter Criteria.status(:todo) & Criteria.priority(:high)
     NoMethodError:
       undefined method `status' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:51:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  7) TodoList supports a disjunction of filters
     Failure/Error: filtered = todo_list.filter Criteria.status(:done) | Criteria.priority(:low)
     NoMethodError:
       undefined method `status' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:56:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  8) TodoList supports a negation of filters
     Failure/Error: filtered = todo_list.filter !Criteria.status(:todo)
     NoMethodError:
       undefined method `status' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:66:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  9) TodoList supports simple filters combination
     Failure/Error: filtered = todo_list.filter Criteria.priority(:high) & !Criteria.tags(['development'])
     NoMethodError:
       undefined method `priority' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:76:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  10) TodoList supports complex filters combination
     Failure/Error: filtered = todo_list.filter Criteria.status(:todo) &
     NoMethodError:
       undefined method `status' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:81:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  11) TodoList can be adjoined with another to-do list
     Failure/Error: development = todo_list.filter Criteria.tags(['development'])
     NoMethodError:
       undefined method `tags' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:97:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  12) TodoList constructs an object for each task
     Failure/Error: task = todo_list.filter(Criteria.tags ['health']).first
     NoMethodError:
       undefined method `tags' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:110:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  13) TodoList returns the number of the tasks todo
     Failure/Error: todo_list.tasks_todo.should eq 5
       
       expected: 5
            got: 0
       
       (compared using ==)
     # /tmp/d20131107-4393-10ex0t9/spec.rb:119:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  14) TodoList returns the number of the tasks in progress
     Failure/Error: todo_list.tasks_in_progress.should eq 2
       
       expected: 2
            got: 0
       
       (compared using ==)
     # /tmp/d20131107-4393-10ex0t9/spec.rb:123:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  15) TodoList returns the number of the completed tasks
     Failure/Error: todo_list.tasks_completed.should eq 2
       
       expected: 2
            got: 0
       
       (compared using ==)
     # /tmp/d20131107-4393-10ex0t9/spec.rb:127:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  16) TodoList checks if all tasks are completed
     Failure/Error: todo_list.filter(Criteria.status :done).completed?.should eq true
     NoMethodError:
       undefined method `status' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:132:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  17) TodoList doesn't modify the to-do list when filtering
     Failure/Error: todo_list.filter(Criteria.status :todo)
     NoMethodError:
       undefined method `status' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:136:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  18) TodoList contains tasks with the neccessary interface
     Failure/Error: task.should respond_to :priority
       expected #<Task:0xb9bb60ac @status=:"      todo", @description="Eat spaghetti.", @priority=:high, @tags=["food", "happiness"]> to respond to :priority
     # /tmp/d20131107-4393-10ex0t9/spec.rb:150:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

  19) TodoList creates a new object on filter
     Failure/Error: todo_list.filter(Criteria.tags %w[wtf]).should_not equal todo_list
     NoMethodError:
       undefined method `tags' for Criteria:Class
     # /tmp/d20131107-4393-10ex0t9/spec.rb:173:in `block (2 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (3 levels) in <top (required)>'
     # ./lib/language/ruby/run_with_timeout.rb:5:in `block (2 levels) in <top (required)>'

Finished in 0.03543 seconds
22 examples, 19 failures

Failed examples:

rspec /tmp/d20131107-4393-10ex0t9/spec.rb:18 # TodoList filters tasks by status
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:25 # TodoList filters tasks by priority
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:35 # TodoList filters tasks by tag
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:39 # TodoList filters tasks by multiple tags
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:46 # TodoList filtering by multiple tags matches only tasks with all the tags
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:50 # TodoList supports a conjuction of filters
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:55 # TodoList supports a disjunction of filters
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:65 # TodoList supports a negation of filters
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:75 # TodoList supports simple filters combination
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:80 # TodoList supports complex filters combination
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:96 # TodoList can be adjoined with another to-do list
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:109 # TodoList constructs an object for each task
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:118 # TodoList returns the number of the tasks todo
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:122 # TodoList returns the number of the tasks in progress
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:126 # TodoList returns the number of the completed tasks
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:130 # TodoList checks if all tasks are completed
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:135 # TodoList doesn't modify the to-do list when filtering
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:145 # TodoList contains tasks with the neccessary interface
rspec /tmp/d20131107-4393-10ex0t9/spec.rb:172 # TodoList creates a new object on filter

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

Ангел обнови решението на 06.11.2013 17:08 (преди над 10 години)

+class Task
+ attr_reader :status, :description, :status, :tags
+ def initialize(arguments)
+ @status = arguments[0].downcase.to_sym
+ @description = arguments[1]
+ @priority = arguments[2].downcase.to_sym
+ @tags = (arguments[3] or "").split(', ')
+ end
+end
+module CriteriaOperations
+ def |(other)
+ #
+ end
+
+ def &(other)
+ #
+ end
+
+ def !(expresion)
+ #
+ end
+end
+class Criteria
+ include CriteriaOperations
+ attr_accessor :priority, :status, :tags
+
+ def initialize()
+ @priority = []
+ @status = []
+ @tags = []
+ end
+
+ def priority(priority_symbol)
+ @priority << priority_symbol
+ end
+
+ def status(status_symbol)
+ @status << status_symbol
+ end
+
+ def tags(tags_array)
+ @tags << tags_array
+ end
+end
+module TodoListStatistics
+ def tasks_todo
+ our_task_list.select { |task| task.status == :todo } .size
+ end
+
+ def tasks_in_progress
+ our_task_list.select { |task| task.status == :current } .size
+ end
+
+ def tasks_completed
+ our_task_list.select { |task| task.status == :done } .size
+ end
+
+ def completed?
+ our_task_list.all? { |task| task.status == :done }
+ end
+end
+class TodoList
+ include Enumerable
+ include TodoListStatistics
+ attr_reader :our_task_list
+
+ @our_task_list = []
+
+ def initialize(arguments)
+ @our_task_list = arguments
+ end
+ def self.parse(text)
+ task_list = []
+ text.split(/\n\t*/).each_with_index do |line|
+ task_list << Task.new(line.split(/ *\| */))
+ end
+ TodoList.new(task_list)
+ end
+ def each
+ @our_task_list.each{ |task| yield task }
+ end
+end