Решение на Втора задача от Георги Пурнаров

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

Към профила на Георги Пурнаров

Резултати

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

Код

class TodoList
attr_accessor :list
def initialize
@list=[]
end
def self.parse(text)
@list=[]
text.split('\n').each { |task| @list.push Task.new task}
self
end
def self.filter criterias
end
def self.completed?
@list.size==self.tasks_competed
end
def self.tasks_todo
@list.map { |task| task.status == :todo}.count(true)
end
def self.tasks_in_progress
@list.map { |task| task.status == :current}.count(true)
end
def self.tasks_competed
@list.map { |task| task.status == :done}.count(true)
end
end
class Task
def initialize (current_task)
fields=current_task.split('|')
fields[3]='' unless fields[3]
@status,@description=fields[0].strip,fields[1].strip
@tags,@priority=fields[3].strip,fields[2].strip
end
def status
@status.downcase.to_sym
end
def description
@description
end
def priority
@priority.downcase.to_sym
end
def tags
@tags.split(',').map {|tag| tag.strip.downcase}
end
end
class Criteria
def self.initialize
end
def self.status input
end
def self.priority input
end
def self.tags input
end
def self.description input
end
end

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

FFFFFFFFFFFFFFFFFFFFF.

Failures:

  1) TodoList filters tasks by status
     Failure/Error: todo_list.filter(Criteria.status :done).map(&:description).should =~ [
     NoMethodError:
       undefined method `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/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 `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/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 `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/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 `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/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 `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/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.map(&:description).should =~ ['Eat spaghetti.', 'Destroy Facebook and Google.', 'Occupy Sofia University.']
     NoMethodError:
       undefined method `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:52: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.map(&:description).should =~ [
     NoMethodError:
       undefined method `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:57: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.map(&:description).should =~ [
     NoMethodError:
       undefined method `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:67: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.map(&:description).should =~ ['Eat spaghetti.', 'Destroy Facebook and Google.', 'Occupy Sofia University.']
     NoMethodError:
       undefined method `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:77: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.map(&:description).should =~ [
     NoMethodError:
       undefined method `map' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:86: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: adjoined    = development.adjoin food
     NoMethodError:
       undefined method `adjoin' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:99: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 `first' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/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: 1
       
       (compared using ==)
     # /tmp/d20131107-4393-1ea0c1t/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-1ea0c1t/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
     NoMethodError:
       undefined method `tasks_completed' for TodoList:Class
     # /tmp/d20131107-4393-1ea0c1t/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 `completed?' for nil:NilClass
     # /tmp/d20131107-4393-1ea0c1t/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.should have(text_input.lines.count).items
     NoMethodError:
       undefined method `items' for TodoList:Class
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:137: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 implements Enumerable
     Failure/Error: todo_list.should respond_to :each
       expected TodoList to respond to :each
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:141: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 contains tasks with the neccessary interface
     Failure/Error: task = todo_list.first
     NoMethodError:
       undefined method `first' for TodoList:Class
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:146: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)>'

  20) TodoList tasks have an array of tags
     Failure/Error: todo_list.first.tags.should be_an Array
     NoMethodError:
       undefined method `first' for TodoList:Class
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:155: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)>'

  21) TodoList preserves the order of tasks
     Failure/Error: todo_list.map(&:description).should eq [
     NoMethodError:
       undefined method `map' for TodoList:Class
     # /tmp/d20131107-4393-1ea0c1t/spec.rb:159: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.03099 seconds
22 examples, 21 failures

Failed examples:

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

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

Георги обнови решението на 05.11.2013 18:53 (преди над 10 години)

+class TodoList
+ attr_accessor :list
+ def initialize
+ @list=[]
+ end
+ def self.parse(text)
+ @list=[]
+ text.split('\n').each { |task| @list.push Task.new task}
+ self
+ end
+ def self.filter criterias
+
+ end
+ def self.completed?
+ @list.size==self.tasks_competed
+ end
+ def self.tasks_todo
+ @list.map { |task| task.status == :todo}.count(true)
+ end
+ def self.tasks_in_progress
+ @list.map { |task| task.status == :current}.count(true)
+ end
+ def self.tasks_competed
+ @list.map { |task| task.status == :done}.count(true)
+ end
+end
+
+class Task
+ def initialize (current_task)
+ fields=current_task.split('|')
+ fields[3]='' unless fields[3]
+ @status,@description=fields[0].strip,fields[1].strip
+ @tags,@priority=fields[3].strip,fields[2].strip
+ end
+ def status
+ @status.downcase.to_sym
+ end
+ def description
+ @description
+ end
+ def priority
+ @priority.downcase.to_sym
+ end
+ def tags
+ @tags.split(',').map {|tag| tag.strip.downcase}
+ end
+end
+
+class Criteria
+ def self.initialize
+ end
+ def self.status input
+ end
+ def self.priority input
+ end
+ def self.tags input
+ end
+ def self.description input
+ end
+end