Решение на Седма задача от Емилия Банчева

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

Към профила на Емилия Банчева

Резултати

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

Код

module LazyMode
class Date
attr_writer :year, :month, :date
def initialize(date)
zero = 4 - date.index('-')
@year = '0' * zero + date[0..(date.index('-') - 1)]
date.slice!(date[0..date.index('-')])
@month = (date[1] != '-') ? date[0..1] : ('0' + date[0])
date.slice!(date[0..date.index('-')])
@day = (date.size == 2) ? date : ('0' + date[0])
end
def year
@year
end
def month
@month
end
def day
@day
end
def to_s
"#{@day} - #{@month} - #{@year}"
end
end
class Note
def initialize(name, *tags)
@name = name
@tags = tags
end
def header
@name
end
def file_name(file_name)
@file_name = file_name
@file_name
end
def body(text = String.new)
yield
@body = text
@body
end
def status(note_status)
yield
case note_status
when :topostpone then :topostpone
when :postponed then :postponed
else :topostpone
end
end
def tags
@tags
end
end
class File
def initialize(file, &block)
@file_name = file
@notes = Array.new(block.call)
end
def note(header, *tags, &block)
new_note = Note.new(header, tags)
new.note.block.call
end
end
end

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

FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF

Failures:

  1) LazyMode LazyMode::Date can parse year
     Failure/Error: expect(date.year).to eq(2012)
       
       expected: 2012
            got: "2012"
       
       (compared using ==)
     # /tmp/d20160107-5693-1paok2t/spec.rb:5:in `block (3 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) LazyMode LazyMode::Date can parse month
     Failure/Error: expect(date.month).to eq(10)
       
       expected: 10
            got: "10"
       
       (compared using ==)
     # /tmp/d20160107-5693-1paok2t/spec.rb:10:in `block (3 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) LazyMode LazyMode::Date can parse day
     Failure/Error: expect(date.day).to eq(3)
       
       expected: 3
            got: "03"
       
       (compared using ==)
     # /tmp/d20160107-5693-1paok2t/spec.rb:15:in `block (3 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) LazyMode LazyMode::Note has file_name
     Failure/Error: file = LazyMode.create_file('my_todos') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:21:in `block (3 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) LazyMode LazyMode::Note has header
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:30:in `block (3 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) LazyMode LazyMode::Note can have nested notes
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:99:in `block (3 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) LazyMode LazyMode::Note #tags has tags
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:40:in `block (4 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) LazyMode LazyMode::Note #tags can have no tags
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:49:in `block (4 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) LazyMode LazyMode::Note #status has status
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:60:in `block (4 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) LazyMode LazyMode::Note #status can have default status
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:69:in `block (4 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) LazyMode LazyMode::Note #body has body
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:80:in `block (4 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) LazyMode LazyMode::Note #body can have no body
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:89:in `block (4 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) LazyMode#daily_agenda returns note scheduled without repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:120:in `block (3 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) LazyMode#daily_agenda returns note scheduled with daily repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:142:in `block (3 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) LazyMode#daily_agenda returns note scheduled with weekly repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:164:in `block (3 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) LazyMode#daily_agenda returns note scheduled with monthly repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:187:in `block (3 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) LazyMode#daily_agenda does not return note whose start date is in the future
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:209:in `block (3 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) LazyMode#daily_agenda returns nested notes
     Failure/Error: file = LazyMode.create_file('nesting') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:220:in `block (3 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) LazyMode#weekly_agenda returns note scheduled without repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:238:in `block (3 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) LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:260:in `block (3 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) LazyMode#weekly_agenda returns note scheduled with weekly repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:284:in `block (3 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)>'

  22) LazyMode#weekly_agenda returns note scheduled with monthly repeater
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:316:in `block (3 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)>'

  23) LazyMode#weekly_agenda does not return note whose start date is in the future
     Failure/Error: file = LazyMode.create_file('file') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:338:in `block (3 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)>'

  24) LazyMode#weekly_agenda returns nested notes
     Failure/Error: file = LazyMode.create_file('nesting') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:349:in `block (3 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)>'

  25) LazyMode#where filters by tag
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:367:in `block (3 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)>'

  26) LazyMode#where filters by body text
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:367:in `block (3 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)>'

  27) LazyMode#where filters by header text
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:367:in `block (3 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)>'

  28) LazyMode#where filters by status
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:367:in `block (3 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)>'

  29) LazyMode#where filters by multiple filters
     Failure/Error: file = LazyMode.create_file('notes') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:367:in `block (3 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)>'

  30) LazyMode.create_file can assign name to files
     Failure/Error: file = LazyMode.create_file('important_notes_and_todos') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:457:in `block (3 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)>'

  31) LazyMode.create_file can build notes in the block
     Failure/Error: file = LazyMode.create_file('not_important') do
     NoMethodError:
       undefined method `create_file' for LazyMode:Module
     # /tmp/d20160107-5693-1paok2t/spec.rb:464:in `block (3 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.01601 seconds
31 examples, 31 failures

Failed examples:

rspec /tmp/d20160107-5693-1paok2t/spec.rb:3 # LazyMode LazyMode::Date can parse year
rspec /tmp/d20160107-5693-1paok2t/spec.rb:8 # LazyMode LazyMode::Date can parse month
rspec /tmp/d20160107-5693-1paok2t/spec.rb:13 # LazyMode LazyMode::Date can parse day
rspec /tmp/d20160107-5693-1paok2t/spec.rb:20 # LazyMode LazyMode::Note has file_name
rspec /tmp/d20160107-5693-1paok2t/spec.rb:29 # LazyMode LazyMode::Note has header
rspec /tmp/d20160107-5693-1paok2t/spec.rb:98 # LazyMode LazyMode::Note can have nested notes
rspec /tmp/d20160107-5693-1paok2t/spec.rb:39 # LazyMode LazyMode::Note #tags has tags
rspec /tmp/d20160107-5693-1paok2t/spec.rb:48 # LazyMode LazyMode::Note #tags can have no tags
rspec /tmp/d20160107-5693-1paok2t/spec.rb:59 # LazyMode LazyMode::Note #status has status
rspec /tmp/d20160107-5693-1paok2t/spec.rb:68 # LazyMode LazyMode::Note #status can have default status
rspec /tmp/d20160107-5693-1paok2t/spec.rb:79 # LazyMode LazyMode::Note #body has body
rspec /tmp/d20160107-5693-1paok2t/spec.rb:88 # LazyMode LazyMode::Note #body can have no body
rspec /tmp/d20160107-5693-1paok2t/spec.rb:119 # LazyMode#daily_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-1paok2t/spec.rb:141 # LazyMode#daily_agenda returns note scheduled with daily repeater
rspec /tmp/d20160107-5693-1paok2t/spec.rb:163 # LazyMode#daily_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-1paok2t/spec.rb:186 # LazyMode#daily_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-1paok2t/spec.rb:208 # LazyMode#daily_agenda does not return note whose start date is in the future
rspec /tmp/d20160107-5693-1paok2t/spec.rb:219 # LazyMode#daily_agenda returns nested notes
rspec /tmp/d20160107-5693-1paok2t/spec.rb:237 # LazyMode#weekly_agenda returns note scheduled without repeater
rspec /tmp/d20160107-5693-1paok2t/spec.rb:259 # LazyMode#weekly_agenda returns multiple notes with different dates when scheduled with daily repeater
rspec /tmp/d20160107-5693-1paok2t/spec.rb:283 # LazyMode#weekly_agenda returns note scheduled with weekly repeater
rspec /tmp/d20160107-5693-1paok2t/spec.rb:315 # LazyMode#weekly_agenda returns note scheduled with monthly repeater
rspec /tmp/d20160107-5693-1paok2t/spec.rb:337 # LazyMode#weekly_agenda does not return note whose start date is in the future
rspec /tmp/d20160107-5693-1paok2t/spec.rb:348 # LazyMode#weekly_agenda returns nested notes
rspec /tmp/d20160107-5693-1paok2t/spec.rb:390 # LazyMode#where filters by tag
rspec /tmp/d20160107-5693-1paok2t/spec.rb:408 # LazyMode#where filters by body text
rspec /tmp/d20160107-5693-1paok2t/spec.rb:420 # LazyMode#where filters by header text
rspec /tmp/d20160107-5693-1paok2t/spec.rb:432 # LazyMode#where filters by status
rspec /tmp/d20160107-5693-1paok2t/spec.rb:443 # LazyMode#where filters by multiple filters
rspec /tmp/d20160107-5693-1paok2t/spec.rb:456 # LazyMode.create_file can assign name to files
rspec /tmp/d20160107-5693-1paok2t/spec.rb:463 # LazyMode.create_file can build notes in the block

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

Емилия обнови решението на 21.12.2015 16:32 (преди около 9 години)

+module LazyMode
+ class Date
+
+ attr_writer :year, :month, :date
+ def initialize(date)
+
+ zero = 4 - date.index('-')
+
+ @year = '0' * zero + date[0..(date.index('-') - 1)]
+
+ date.slice!(date[0..date.index('-')])
+
+ @month = (date[1] != '-') ? date[0..1] : ('0' + date[0])
+
+ date.slice!(date[0..date.index('-')])
+
+ @day = (date.size == 2) ? date : ('0' + date[0])
+ end
+
+ def year
+
+ @year
+
+ end
+
+ def month
+
+ @month
+
+ end
+
+ def day
+
+ @day
+
+ end
+
+ def to_s
+
+ "#{@day} - #{@month} - #{@year}"
+ end
+
+ end
+
+
+ class Note
+
+ def initialize(name, *tags)
+
+ @name = name
+
+ @tags = tags
+
+ end
+
+ def header
+
+ @name
+
+ end
+
+ def file_name(file_name)
+
+ @file_name = file_name
+
+ @file_name
+
+ end
+
+ def body(text = String.new)
+ yield
+ @body = text
+
+ @body
+
+ end
+
+ def status(note_status)
+
+ yield
+ case note_status
+
+ when :topostpone then :topostpone
+
+ when :postponed then :postponed
+
+ else :topostpone
+
+ end
+
+ end
+
+ def tags
+
+ @tags
+
+ end
+ end
+
+ class File
+
+ def initialize(file, &block)
+
+ @file_name = file
+
+ @notes = Array.new(block.call)
+
+ end
+
+ def note(header, *tags, &block)
+ new_note = Note.new(header, tags)
+
+ new.note.block.call
+
+ end
+
+ end
+end