Решение на Четвърта задача от Александър Стефанов

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

Към профила на Александър Стефанов

Резултати

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

Код

module UI
class Horizontal
@arr_items
@border
@style
def initialize(hash, &block)
@border = hash[:border]
@style = hash[:style]
instance_eval &block
end
def horizontal(hash, &block)
horizon = Horizontal.new hash(&block)
@arr_items << horizon
end
def vertical(hash, &block)
vertical = Vertical.new hash(&block)
@arr_items << vertical
end
def label(parameters)
parameters[:border] = "" unless parameters.has_key?(:border)
style = TextScreen::style(parameters[:style], parameters[:text])
@str << parameters[:border] << style << parameters[:border]
@arr_items << @str
end
def top
end
def get_top
@border << @border unless border.nil?
end
end
class Vertical
@arr_items
@border
@style
def initialize(hash, &block)
@border = hash[:border]
@style = hash[:style]
instance_eval &block
end
def horizontal(hash, &block)
horizon = Horizontal.new hash(&block)
@arr_items << horizon
end
def vertical(hash, &block)
vertical = Vertical.new(hash, &block)
@arr_items << vertical
end
def label(parameters)
parameters[:border] = "" unless parameters.has_key?(:border)
style = TextScreen::style(parameters[:style], parameters[:text])
@str << parameters[:border] << style << parameters[:border]
@arr_items << @str
end
def top
end
def get_top
@border << @border unless border.nil?
end
end
class TextScreen
@screen_string = ""
def self.style (style, text)
case style
when :uppercase then text.upcase
when :downcase then text.downcase
else text
end
end
def print(group)
group.each do |elem|
@screen_string << elem.get_top
end
end
def self.draw(&block)
group = Hroizontal.new &block
print group
@screen_string
end
end
end

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

FFFFFFFFFF.

Failures:

  1) Command Line Toolkit arranges components horizontally by default
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:20: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 adding horizontal group does not change the behavior
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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)>'

  3) Command Line Toolkit verical group orders elements vertically
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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)>'

  4) Command Line Toolkit handles complex group nestings
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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)>'

  5) Command Line Toolkit wraps vertically-aligned components correctly in border
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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)>'

  6) Command Line Toolkit handles borders correctly in complex group nestings
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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)>'

  7) Command Line Toolkit applies upcase to simple components
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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)>'

  8) Command Line Toolkit propagates upcase to child components
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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)>'

  9) Command Line Toolkit applies downcase to simple components
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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)>'

  10) Command Line Toolkit propagates downcase to child components
     Failure/Error: actual_text   = rstrip_lines.call(UI::TextScreen.draw(&actual).to_s)
     NameError:
       uninitialized constant UI::TextScreen::Hroizontal
     # /tmp/d20141126-26053-iwnfcr/solution.rb:75:in `draw'
     # /tmp/d20141126-26053-iwnfcr/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-iwnfcr/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.03385 seconds
11 examples, 10 failures

Failed examples:

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

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

Александър обнови решението на 26.11.2014 16:26 (преди почти 10 години)

+module UI
+ class Horizontal
+ @arr_items
+ @border
+ @style
+ def initialize(hash, &block)
+ @border = hash[:border]
+ @style = hash[:style]
+ instance_eval &block
+ end
+ def horizontal(hash, &block)
+ horizon = Horizontal.new hash(&block)
+ @arr_items << horizon
+ end
+ def vertical(hash, &block)
+ vertical = Vertical.new hash(&block)
+ @arr_items << vertical
+ end
+ def label(parameters)
+ parameters[:border] = "" unless parameters.has_key?(:border)
+ style = TextScreen::style(parameters[:style], parameters[:text])
+ @str << parameters[:border] << style << parameters[:border]
+ @arr_items << @str
+ end
+ def top
+ end
+ def get_top
+ @border << @border unless border.nil?
+ end
+ end
+ class Vertical
+ @arr_items
+ @border
+ @style
+ def initialize(hash, &block)
+ @border = hash[:border]
+ @style = hash[:style]
+ instance_eval &block
+ end
+ def horizontal(hash, &block)
+ horizon = Horizontal.new hash(&block)
+ @arr_items << horizon
+ end
+ def vertical(hash, &block)
+ vertical = Vertical.new(hash, &block)
+ @arr_items << vertical
+ end
+ def label(parameters)
+ parameters[:border] = "" unless parameters.has_key?(:border)
+ style = TextScreen::style(parameters[:style], parameters[:text])
+ @str << parameters[:border] << style << parameters[:border]
+ @arr_items << @str
+ end
+ def top
+ end
+ def get_top
+ @border << @border unless border.nil?
+ end
+ end
+ class TextScreen
+ @screen_string = ""
+ def self.style (style, text)
+ case style
+ when :uppercase then text.upcase
+ when :downcase then text.downcase
+ else text
+ end
+ end
+ def print(group)
+ group.each do |elem|
+ @screen_string << elem.get_top
+ end
+ end
+ def self.draw(&block)
+ group = Hroizontal.new &block
+ print group
+ @screen_string
+ end
+ end
+end