Решение на Четвърта задача от Димитър Шукерски

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

Към профила на Димитър Шукерски

Резултати

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

Код

module UI
class TextScreen
def self.draw(&block)
UI::TextScreen.new.draw(&block)
end
def initialize
@contents = ""
end
def draw(&block)
instance_eval(&block)
@contents
end
def vertical(&block)
@add_new_line = true
instance_eval(&block)
end
def horizontal(&block)
if @add_new_line
@add_new_line = false
instance_eval(&block)
@contents += "\n"
@add_new_line = true
end
end
def label(args)
args[:border] ||= ''
@contents += "#{args[:border]}#{args[:text]}#{args[:border]}"
@contents += "\n" if @add_new_line
end
end
end

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

.F.FFFFFFF.

Failures:

  1) Command Line Toolkit adding horizontal group does not change the behavior
     Failure/Error: expect do
       expected #<Proc:0xb990b5b4@/tmp/d20141126-26053-ptc4ve/spec.rb:30> to render as "      123\n"
     # /tmp/d20141126-26053-ptc4ve/spec.rb:30: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) Command Line Toolkit handles complex group nestings
     Failure/Error: expect do
       expected #<Proc:0xb9908738@/tmp/d20141126-26053-ptc4ve/spec.rb:56> to render as "      123\n        45\n         6\n      7\n"
     # /tmp/d20141126-26053-ptc4ve/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)>'

  3) Command Line Toolkit wraps vertically-aligned components correctly in border
     Failure/Error: vertical border: '|' do
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20141126-26053-ptc4ve/solution.rb:18:in `vertical'
     # /tmp/d20141126-26053-ptc4ve/spec.rb:86:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-ptc4ve/solution.rb:14:in `instance_eval'
     # /tmp/d20141126-26053-ptc4ve/solution.rb:14:in `draw'
     # /tmp/d20141126-26053-ptc4ve/solution.rb:6:in `draw'
     # /tmp/d20141126-26053-ptc4ve/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-ptc4ve/spec.rb:85: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) Command Line Toolkit handles borders correctly in complex group nestings
     Failure/Error: vertical border: '|' do
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20141126-26053-ptc4ve/solution.rb:18:in `vertical'
     # /tmp/d20141126-26053-ptc4ve/spec.rb:100:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-ptc4ve/solution.rb:14:in `instance_eval'
     # /tmp/d20141126-26053-ptc4ve/solution.rb:14:in `draw'
     # /tmp/d20141126-26053-ptc4ve/solution.rb:6:in `draw'
     # /tmp/d20141126-26053-ptc4ve/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-ptc4ve/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)>'

  5) Command Line Toolkit applies upcase to simple components
     Failure/Error: expect do
       expected #<Proc:0xb98ebd18@/tmp/d20141126-26053-ptc4ve/spec.rb:128> to render as "      SOMEvery\n"
     # /tmp/d20141126-26053-ptc4ve/spec.rb:128: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) Command Line Toolkit propagates upcase to child components
     Failure/Error: expect do
       expected #<Proc:0xb98e3a3c@/tmp/d20141126-26053-ptc4ve/spec.rb:137> to render as "      someveryINTERESTINGget it?\n              TEXTGOES       \n                  HERE       \n"
     # /tmp/d20141126-26053-ptc4ve/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)>'

  7) Command Line Toolkit applies downcase to simple components
     Failure/Error: expect do
       expected #<Proc:0xb98e0d8c@/tmp/d20141126-26053-ptc4ve/spec.rb:163> to render as "      SOMEvery\n"
     # /tmp/d20141126-26053-ptc4ve/spec.rb:163: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) Command Line Toolkit propagates downcase to child components
     Failure/Error: expect do
       expected #<Proc:0xb98d7264@/tmp/d20141126-26053-ptc4ve/spec.rb:172> to render as "      SOMEVERYinterestingGET IT?\n              textgoes       \n                  here       \n"
     # /tmp/d20141126-26053-ptc4ve/spec.rb:172: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.02182 seconds
11 examples, 8 failures

Failed examples:

rspec /tmp/d20141126-26053-ptc4ve/spec.rb:29 # Command Line Toolkit adding horizontal group does not change the behavior
rspec /tmp/d20141126-26053-ptc4ve/spec.rb:55 # Command Line Toolkit handles complex group nestings
rspec /tmp/d20141126-26053-ptc4ve/spec.rb:84 # Command Line Toolkit wraps vertically-aligned components correctly in border
rspec /tmp/d20141126-26053-ptc4ve/spec.rb:98 # Command Line Toolkit handles borders correctly in complex group nestings
rspec /tmp/d20141126-26053-ptc4ve/spec.rb:127 # Command Line Toolkit applies upcase to simple components
rspec /tmp/d20141126-26053-ptc4ve/spec.rb:136 # Command Line Toolkit propagates upcase to child components
rspec /tmp/d20141126-26053-ptc4ve/spec.rb:162 # Command Line Toolkit applies downcase to simple components
rspec /tmp/d20141126-26053-ptc4ve/spec.rb:171 # Command Line Toolkit propagates downcase to child components

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

Димитър обнови решението на 26.11.2014 15:40 (преди почти 10 години)

+module UI
+
+ class TextScreen
+
+ def self.draw(&block)
+ UI::TextScreen.new.draw(&block)
+ end
+
+ def initialize
+ @contents = ""
+ end
+
+ def draw(&block)
+ instance_eval(&block)
+ @contents
+ end
+
+ def vertical(&block)
+ @add_new_line = true
+ instance_eval(&block)
+ @add_new_line = false
+ end
+
+ def horizontal(&block)
+ instance_eval(&block)
+ end
+
+
+ def label(*args)
+ @contents += args[0][:text]
+ @contents += "\n" if @add_new_line
+ end
+ end
+end

Димитър обнови решението на 26.11.2014 16:29 (преди почти 10 години)

module UI
class TextScreen
def self.draw(&block)
UI::TextScreen.new.draw(&block)
end
def initialize
@contents = ""
end
def draw(&block)
instance_eval(&block)
@contents
end
def vertical(&block)
@add_new_line = true
instance_eval(&block)
- @add_new_line = false
end
def horizontal(&block)
- instance_eval(&block)
+ if @add_new_line
+ @add_new_line = false
+ instance_eval(&block)
+ @contents += "\n"
+ @add_new_line = true
+ end
end
-
def label(*args)
@contents += args[0][:text]
@contents += "\n" if @add_new_line
end
end
end

Димитър обнови решението на 26.11.2014 16:58 (преди почти 10 години)

module UI
class TextScreen
def self.draw(&block)
UI::TextScreen.new.draw(&block)
end
def initialize
@contents = ""
end
def draw(&block)
instance_eval(&block)
@contents
end
def vertical(&block)
@add_new_line = true
instance_eval(&block)
end
def horizontal(&block)
if @add_new_line
- @add_new_line = false
- instance_eval(&block)
- @contents += "\n"
- @add_new_line = true
+ @add_new_line = false
+ instance_eval(&block)
+ @contents += "\n"
+ @add_new_line = true
end
end
- def label(*args)
- @contents += args[0][:text]
+ def label(args)
+ args[:border] ||= ''
+ @contents += "#{args[:border]}#{args[:text]}#{args[:border]}"
@contents += "\n" if @add_new_line
end
- end
+ end
end