Решение на Четвърта задача от Ралица Великова

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

Към профила на Ралица Великова

Резултати

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

Код

#temporary
module UI
class TextScreen
attr_accessor :text
def initialize()
@text = ''
@alignment = ''
end
def self.draw(&block)
screen_text = TextScreen.new
screen_text.instance_eval(&block).to_s if block_given?
end
def label(text:, border: nil, style: nil)
@text << border.to_s
@text << text
@text << border.to_s
@text << @alignment
end
def vertical(&block)
@alignment = "\n"
self.instance_eval(&block).strip
end
def horizontal(&block)
@alignment = " "
self.instance_eval(&block).strip
end
end
end

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

.F.FFFFFFF.

Failures:

  1) Command Line Toolkit adding horizontal group does not change the behavior
     Failure/Error: expect do
       expected #<Proc:0xb96df740@/tmp/d20141126-26053-lkvrif/spec.rb:30> to render as "      123\n"
     # /tmp/d20141126-26053-lkvrif/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:0xb96dc734@/tmp/d20141126-26053-lkvrif/spec.rb:56> to render as "      123\n        45\n         6\n      7\n"
     # /tmp/d20141126-26053-lkvrif/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-lkvrif/solution.rb:24:in `vertical'
     # /tmp/d20141126-26053-lkvrif/spec.rb:86:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/solution.rb:14:in `instance_eval'
     # /tmp/d20141126-26053-lkvrif/solution.rb:14:in `draw'
     # /tmp/d20141126-26053-lkvrif/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/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-lkvrif/solution.rb:24:in `vertical'
     # /tmp/d20141126-26053-lkvrif/spec.rb:100:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/solution.rb:14:in `instance_eval'
     # /tmp/d20141126-26053-lkvrif/solution.rb:14:in `draw'
     # /tmp/d20141126-26053-lkvrif/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/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:0xb96bfdf0@/tmp/d20141126-26053-lkvrif/spec.rb:128> to render as "      SOMEvery\n"
     # /tmp/d20141126-26053-lkvrif/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: vertical style: :upcase do
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20141126-26053-lkvrif/solution.rb:24:in `vertical'
     # /tmp/d20141126-26053-lkvrif/spec.rb:142:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/solution.rb:31:in `instance_eval'
     # /tmp/d20141126-26053-lkvrif/solution.rb:31:in `horizontal'
     # /tmp/d20141126-26053-lkvrif/spec.rb:138:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/solution.rb:14:in `instance_eval'
     # /tmp/d20141126-26053-lkvrif/solution.rb:14:in `draw'
     # /tmp/d20141126-26053-lkvrif/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/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:0xb96b5d28@/tmp/d20141126-26053-lkvrif/spec.rb:163> to render as "      SOMEvery\n"
     # /tmp/d20141126-26053-lkvrif/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: vertical style: :downcase do
     ArgumentError:
       wrong number of arguments (1 for 0)
     # /tmp/d20141126-26053-lkvrif/solution.rb:24:in `vertical'
     # /tmp/d20141126-26053-lkvrif/spec.rb:177:in `block (4 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/solution.rb:31:in `instance_eval'
     # /tmp/d20141126-26053-lkvrif/solution.rb:31:in `horizontal'
     # /tmp/d20141126-26053-lkvrif/spec.rb:173:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/solution.rb:14:in `instance_eval'
     # /tmp/d20141126-26053-lkvrif/solution.rb:14:in `draw'
     # /tmp/d20141126-26053-lkvrif/spec.rb:8:in `block (3 levels) in <top (required)>'
     # /tmp/d20141126-26053-lkvrif/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.0789 seconds
11 examples, 8 failures

Failed examples:

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

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

Ралица обнови решението на 23.11.2014 23:15 (преди около 10 години)

+#temporary
+
+module UI
+ class TextScreen
+ attr_accessor :text
+
+ def initialize()
+ @text = ''
+ @alignment = ''
+ end
+
+ def self.draw(&block)
+ screen_text = TextScreen.new
+ screen_text.instance_eval(&block).to_s if block_given?
+ end
+
+ def label(text:, border: nil, style: nil)
+ @text << border.to_s
+ @text << text
+ @text << border.to_s
+ @text << @alignment
+ end
+
+ def vertical(&block)
+ @alignment = "\n"
+ self.instance_eval(&block).strip
+ end
+
+ def horizontal(&block)
+ @alignment = " "
+ self.instance_eval(&block).strip
+ end
+ end
+end