Решение на Четвърта задача от Любомир Папазов

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

Към профила на Любомир Папазов

Резултати

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

Код

module UI
class TextScreen
def initialize
@texts = []
@border = nil
end
def self.draw(&block)
text_screen = TextScreen.new
text_screen.instance_eval(&block)
text_screen
end
def label(**hash)
@texts << hash[:text]
end
def to_s
res = @texts.join
end
def vertical(&block)
vertical = Vertical.new(&block)
puts vertical
end
def horizontal(&block)
horizontal = Horizontal.new(&block)
puts horizontal
end
end
class Horizontal
def initialize(&block)
screen = text_screen.new.instance_eval &block
@screen = screen
end
def to_s
result = @screen.join
end
end
class Vertical
def initialize(&block)
screen = TextScreen.new.instance_eval(&block)
@screen = screen
end
def to_s
result = @screen.join("\n")
end
end
end

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

.F1
2
3
FFFFFFFF.

Failures:

  1) Command Line Toolkit adding horizontal group does not change the behavior
     Failure/Error: horizontal do
     NameError:
       undefined local variable or method `text_screen' for #<UI::Horizontal:0xba080a9c>
     # /tmp/d20141126-26053-x896u3/solution.rb:35:in `initialize'
     # /tmp/d20141126-26053-x896u3/solution.rb:28:in `new'
     # /tmp/d20141126-26053-x896u3/solution.rb:28:in `horizontal'
     # /tmp/d20141126-26053-x896u3/spec.rb:31:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `instance_eval'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `draw'
     # /tmp/d20141126-26053-x896u3/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/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 verical group orders elements vertically
     Failure/Error: expect do
       expected #<Proc:0xba07bfd8@/tmp/d20141126-26053-x896u3/spec.rb:42> to render as "      1\n      2\n      3\n"
     # /tmp/d20141126-26053-x896u3/spec.rb:42: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 handles complex group nestings
     Failure/Error: horizontal do
     NameError:
       undefined local variable or method `text_screen' for #<UI::Horizontal:0xba079044>
     # /tmp/d20141126-26053-x896u3/solution.rb:35:in `initialize'
     # /tmp/d20141126-26053-x896u3/solution.rb:28:in `new'
     # /tmp/d20141126-26053-x896u3/solution.rb:28:in `horizontal'
     # /tmp/d20141126-26053-x896u3/spec.rb:58:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/solution.rb:46:in `instance_eval'
     # /tmp/d20141126-26053-x896u3/solution.rb:46:in `initialize'
     # /tmp/d20141126-26053-x896u3/solution.rb:23:in `new'
     # /tmp/d20141126-26053-x896u3/solution.rb:23:in `vertical'
     # /tmp/d20141126-26053-x896u3/spec.rb:57:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `instance_eval'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `draw'
     # /tmp/d20141126-26053-x896u3/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/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)>'

  4) 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-x896u3/solution.rb:22:in `vertical'
     # /tmp/d20141126-26053-x896u3/spec.rb:86:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `instance_eval'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `draw'
     # /tmp/d20141126-26053-x896u3/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/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)>'

  5) 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-x896u3/solution.rb:22:in `vertical'
     # /tmp/d20141126-26053-x896u3/spec.rb:100:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `instance_eval'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `draw'
     # /tmp/d20141126-26053-x896u3/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/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)>'

  6) Command Line Toolkit applies upcase to simple components
     Failure/Error: expect do
       expected #<Proc:0xba0758e0@/tmp/d20141126-26053-x896u3/spec.rb:128> to render as "      SOMEvery\n"
     # /tmp/d20141126-26053-x896u3/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)>'

  7) Command Line Toolkit propagates upcase to child components
     Failure/Error: horizontal do
     NameError:
       undefined local variable or method `text_screen' for #<UI::Horizontal:0xba0631a4>
     # /tmp/d20141126-26053-x896u3/solution.rb:35:in `initialize'
     # /tmp/d20141126-26053-x896u3/solution.rb:28:in `new'
     # /tmp/d20141126-26053-x896u3/solution.rb:28:in `horizontal'
     # /tmp/d20141126-26053-x896u3/spec.rb:138:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `instance_eval'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `draw'
     # /tmp/d20141126-26053-x896u3/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/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)>'

  8) Command Line Toolkit applies downcase to simple components
     Failure/Error: expect do
       expected #<Proc:0xba061df4@/tmp/d20141126-26053-x896u3/spec.rb:163> to render as "      SOMEvery\n"
     # /tmp/d20141126-26053-x896u3/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)>'

  9) Command Line Toolkit propagates downcase to child components
     Failure/Error: horizontal do
     NameError:
       undefined local variable or method `text_screen' for #<UI::Horizontal:0xba058ccc>
     # /tmp/d20141126-26053-x896u3/solution.rb:35:in `initialize'
     # /tmp/d20141126-26053-x896u3/solution.rb:28:in `new'
     # /tmp/d20141126-26053-x896u3/solution.rb:28:in `horizontal'
     # /tmp/d20141126-26053-x896u3/spec.rb:173:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `instance_eval'
     # /tmp/d20141126-26053-x896u3/solution.rb:10:in `draw'
     # /tmp/d20141126-26053-x896u3/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-x896u3/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.01991 seconds
11 examples, 9 failures

Failed examples:

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

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

Любомир обнови решението на 26.11.2014 12:25 (преди почти 10 години)

+module UI
+ class TextScreen
+ def initialize
+ @texts = []
+ @border = nil
+ end
+
+ def self.draw(&block)
+ text_screen = TextScreen.new
+ text_screen.instance_eval(&block)
+ text_screen
+ end
+
+ def label(**hash)
+ @texts << hash[:text]
+ end
+
+ def to_s
+ res = @texts.join
+ end
+
+ def vertical(&block)
+ vertical = Vertical.new(&block)
+ puts vertical
+ end
+
+ def horizontal(&block)
+ horizontal = Horizontal.new(&block)
+ puts horizontal
+ end
+ end
+
+ class Horizontal
+ def initialize(&block)
+ screen = text_screen.new.instance_eval &block
+ @screen = screen
+ end
+
+ def to_s
+ result = @screen.join
+ end
+ end
+
+ class Vertical
+ def initialize(&block)
+ screen = TextScreen.new.instance_eval(&block)
+ @screen = screen
+ end
+
+ def to_s
+ result = @screen.join("\n")
+ end
+ end
+end