Решение на Четвърта задача от Гюлджан Купен

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

Към профила на Гюлджан Купен

Резултати

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

Код

module UI
class Methods
@@text = ''
@@orientation = 0
def style(symbol)
case symbol
when :upcase then @@text.upcase!
when :downcase then @@text.downcase!
when :nil then @@text
end
end
def label(text:, border: nil, style: nil)
@@text << text
border ? @@text.insert(0, border).insert(@@text.length, border) : nil
@@orientation == 1 ? insert : nil
style(style)
@@text
end
def insert
@@text << "\n"
end
def self.change
@@text = ''
end
def horizontal(border: nil, style: nil, &block)
@@orientation = 0
block.call
end
def vertical(border: nil, style: nil, &block)
@@orientation = 1
block.call
end
end
class TextScreen
@@used = 0
def self.draw(&block)
change
@@used = 1
p = Methods.new
p.instance_eval &block
end
def self.change
if @@used == 1
Methods.change
end
end
end
end

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

...FFFFFFF.

Failures:

  1) Command Line Toolkit handles complex group nestings
     Failure/Error: expect do
       expected #<Proc:0xba4f03fc@/tmp/d20141126-26053-d5fwgt/spec.rb:56> to render as "      123\n        45\n         6\n      7\n"
     # /tmp/d20141126-26053-d5fwgt/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)>'

  2) Command Line Toolkit wraps vertically-aligned components correctly in border
     Failure/Error: expect do
       expected #<Proc:0xba4ed6e8@/tmp/d20141126-26053-d5fwgt/spec.rb:85> to render as "      |something|\n      |some     |\n      |soommee  |\n"
     # /tmp/d20141126-26053-d5fwgt/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)>'

  3) Command Line Toolkit handles borders correctly in complex group nestings
     Failure/Error: expect do
       expected #<Proc:0xba4e5420@/tmp/d20141126-26053-d5fwgt/spec.rb:99> to render as "      |||1||2|||3|       |||\n      ||      |||4|||5||||||\n      ||      ||   ||6||||||\n      ||7|                 |\n"
     # /tmp/d20141126-26053-d5fwgt/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)>'

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

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

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

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

Failed examples:

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

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

Гюлджан обнови решението на 26.11.2014 09:45 (преди над 9 години)

+module UI
+ class Methods
+ @@text = ''
+ @@orientation = 0
+
+ def style(symbol)
+ case symbol
+ when :upcase then @@text.upcase!
+ when :downcase then @@text.downcase!
+ when :nil then @@text
+ end
+ end
+
+ def label(text:, border: nil, style: nil)
+ @@text << text
+ border ? @@text.insert(0, border).insert(@@text.length, border) : nil
+ @@orientation == 1 ? insert : nil
+ style(style)
+ @@text
+ end
+
+ def insert
+ @@text << "\n"
+ end
+
+ def self.change
+ @@text = ''
+ end
+
+ def horizontal(border: nil, style: nil, &block)
+ @@orientation = 0
+ block.call
+ end
+
+ def vertical(border: nil, style: nil, &block)
+ @@orientation = 1
+ block.call
+ end
+ end
+
+ class TextScreen
+ @@used = 0
+ def self.draw(&block)
+ change
+ @@used = 1
+ p = Methods.new
+ p.instance_eval &block
+ end
+
+ def self.change
+ if @@used == 1
+ Methods.change
+ end
+ end
+ end
+end