Решение на Шеста задача от Малина Демирова

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

Към профила на Малина Демирова

Резултати

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

Код

module TurtleGraphics
#I did not have much time, but i will be glad of at least a small comment
class Turtle
attr_accessor :position, :rows, :cols, :marks
attr_reader :left, :right, :commands
def initialize(rows, cols)
@rows = rows
@cols = cols
@position, @marks = Array.new(@rows) { Array.new(@cols, 0) }, []
@commands
end
def move
@position += 1
end
def mark
marks << @position
end
COMMAND = [:move, :mark, :turn_right, :turn_left].freeze
COMMAND.each do |command_name|
define_method command_name do | *arguments |
@instructions << [command_name, *arguments]
end
end
def self.draw
turtle = Turtle.new position
turtle.instance_eval &commands
turtle.commands
case commands
when 'move' then puts '1'
when 'mark' then puts '4'
when 'turn_right' then puts '2'
when 'turn_left' then puts '3'
end
end
end
class Canvas
attr_reader :canvas
def initialize(canvas)
@canvas = canvas
end
class HTML
attr_reader :pixels
def initialize(pixels)
@pixels = pixels
end
def set_values(width, height)
@pixels[[width, height]] = true
end
TEMPLATE = '<!DOCTYPE html>
<html>
<head>
<title>Turtle graphics</title>
<style>
table {
border-spacing: 0;
}
tr {
padding: 0;
}
td {
width: 5px;
height: 5px;
background-color: black;
padding: 0;
}
</style>
</head>
<body>
<table>
<tr>
<td style="opacity: 1.00"></td>
<td style="opacity: 1.00"></td>
<td style="opacity: 0.00"></td>
</tr>
<tr>
<td style="opacity: 0.00"></td>
<td style="opacity: 1.00"></td>
<td style="opacity: 1.00"></td>
</tr>
<tr>
<td style="opacity: 0.00"></td>
<td style="opacity: 0.00"></td>
<td style="opacity: 0.00"></td>
</tr>
</table>
</body>
</html>'.freeze
def render
TEMPLATE % super
end
end
end
end

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

FFFFFFFFFFFFFF

Failures:

  1) TurtleGraphics renders a complex shape
     Failure/Error: canvas = TurtleGraphics::Turtle.new(20, 20).draw do
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f9241fa0>
     # /tmp/d20151203-5272-33lskz/spec.rb:265: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) TurtleGraphics Turtle #draw #move marks where the turtle has moved
     Failure/Error: TurtleGraphics::Turtle.new(2, 2).draw(&block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f923a688>
     # /tmp/d20151203-5272-33lskz/spec.rb:4:in `create_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:10:in `block (5 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) TurtleGraphics Turtle #draw #move moves the turtle to the start of row or column when we are at its end
     Failure/Error: TurtleGraphics::Turtle.new(2, 2).draw(&block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f92378c0>
     # /tmp/d20151203-5272-33lskz/spec.rb:4:in `create_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:15:in `block (5 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) TurtleGraphics Turtle #draw #move keeps the orientation when we get out of column
     Failure/Error: TurtleGraphics::Turtle.new(2, 2).draw(&block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f9235908>
     # /tmp/d20151203-5272-33lskz/spec.rb:4:in `create_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:34:in `block (5 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) TurtleGraphics Turtle #draw #move counts the times we have passed through every cell
     Failure/Error: TurtleGraphics::Turtle.new(2, 2).draw(&block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f922f148>
     # /tmp/d20151203-5272-33lskz/spec.rb:4:in `create_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:46:in `block (5 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) TurtleGraphics Turtle #draw #turn_right turns the orienation of the turtle right of where we stand
     Failure/Error: TurtleGraphics::Turtle.new(2, 2).draw(&block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f922a508>
     # /tmp/d20151203-5272-33lskz/spec.rb:4:in `create_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:56:in `block (5 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) TurtleGraphics Turtle #draw #turn_left turns the orienation of the turtle left of where we stand
     Failure/Error: TurtleGraphics::Turtle.new(2, 2).draw(&block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f92148e8>
     # /tmp/d20151203-5272-33lskz/spec.rb:4:in `create_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:74:in `block (5 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) TurtleGraphics Turtle #draw #spawn_at moves the turtle to an exact location in the start
     Failure/Error: TurtleGraphics::Turtle.new(2, 2).draw(&block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f8ea8ec0>
     # /tmp/d20151203-5272-33lskz/spec.rb:4:in `create_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:92:in `block (5 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) TurtleGraphics Turtle #draw #look turns the turtle based on where it should look
     Failure/Error: TurtleGraphics::Turtle.new(2, 2).draw(&block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f8e95438>
     # /tmp/d20151203-5272-33lskz/spec.rb:4:in `create_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:99:in `block (5 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) TurtleGraphics Canvas::ASCII renders the proper symbols depending on the intensity
     Failure/Error: ascii_canvas = TurtleGraphics::Canvas::ASCII.new(['0', '1', '2', '3'])
     NameError:
       uninitialized constant TurtleGraphics::Canvas::ASCII
     # /tmp/d20151203-5272-33lskz/spec.rb:113:in `block (3 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)>'

  11) TurtleGraphics Canvas::ASCII can render with a different number of symbols
     Failure/Error: ascii_canvas = TurtleGraphics::Canvas::ASCII.new(['z', 'o', 't'])
     NameError:
       uninitialized constant TurtleGraphics::Canvas::ASCII
     # /tmp/d20151203-5272-33lskz/spec.rb:136:in `block (3 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)>'

  12) TurtleGraphics Canvas::HTML renders the proper template
     Failure/Error: TurtleGraphics::Turtle.new(3, 3).draw(html_canvas, &block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f8e3f448>
     # /tmp/d20151203-5272-33lskz/spec.rb:162:in `create_html_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:166:in `block (3 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)>'

  13) TurtleGraphics Canvas::HTML sets the pixel size of the table
     Failure/Error: TurtleGraphics::Turtle.new(3, 3).draw(html_canvas, &block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f8e32770>
     # /tmp/d20151203-5272-33lskz/spec.rb:162:in `create_html_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:219:in `block (3 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)>'

  14) TurtleGraphics Canvas::HTML changes the opacity of a cell based on the times we have passed
     Failure/Error: TurtleGraphics::Turtle.new(3, 3).draw(html_canvas, &block)
     NoMethodError:
       undefined method `draw' for #<TurtleGraphics::Turtle:0x007f02f8e22230>
     # /tmp/d20151203-5272-33lskz/spec.rb:162:in `create_html_canvas'
     # /tmp/d20151203-5272-33lskz/spec.rb:228:in `block (3 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.01116 seconds
14 examples, 14 failures

Failed examples:

rspec /tmp/d20151203-5272-33lskz/spec.rb:264 # TurtleGraphics renders a complex shape
rspec /tmp/d20151203-5272-33lskz/spec.rb:9 # TurtleGraphics Turtle #draw #move marks where the turtle has moved
rspec /tmp/d20151203-5272-33lskz/spec.rb:14 # TurtleGraphics Turtle #draw #move moves the turtle to the start of row or column when we are at its end
rspec /tmp/d20151203-5272-33lskz/spec.rb:33 # TurtleGraphics Turtle #draw #move keeps the orientation when we get out of column
rspec /tmp/d20151203-5272-33lskz/spec.rb:45 # TurtleGraphics Turtle #draw #move counts the times we have passed through every cell
rspec /tmp/d20151203-5272-33lskz/spec.rb:55 # TurtleGraphics Turtle #draw #turn_right turns the orienation of the turtle right of where we stand
rspec /tmp/d20151203-5272-33lskz/spec.rb:73 # TurtleGraphics Turtle #draw #turn_left turns the orienation of the turtle left of where we stand
rspec /tmp/d20151203-5272-33lskz/spec.rb:91 # TurtleGraphics Turtle #draw #spawn_at moves the turtle to an exact location in the start
rspec /tmp/d20151203-5272-33lskz/spec.rb:98 # TurtleGraphics Turtle #draw #look turns the turtle based on where it should look
rspec /tmp/d20151203-5272-33lskz/spec.rb:112 # TurtleGraphics Canvas::ASCII renders the proper symbols depending on the intensity
rspec /tmp/d20151203-5272-33lskz/spec.rb:135 # TurtleGraphics Canvas::ASCII can render with a different number of symbols
rspec /tmp/d20151203-5272-33lskz/spec.rb:165 # TurtleGraphics Canvas::HTML renders the proper template
rspec /tmp/d20151203-5272-33lskz/spec.rb:218 # TurtleGraphics Canvas::HTML sets the pixel size of the table
rspec /tmp/d20151203-5272-33lskz/spec.rb:227 # TurtleGraphics Canvas::HTML changes the opacity of a cell based on the times we have passed

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

Малина обнови решението на 02.12.2015 16:40 (преди над 8 години)

+module TurtleGraphics
+#I did not have much time, but i will be glad of at least a small comment
+class Turtle
+ attr_accessor :position, :rows, :cols, :marks
+ attr_reader :left, :right, :commands
+
+ def initialize(rows, cols)
+ @rows = rows
+ @cols = cols
+ @position, @marks = Array.new(@rows) { Array.new(@cols, 0) }, []
+ @commands
+ end
+
+ def move
+ @position += 1
+ end
+
+ def mark
+ marks << @position
+ end
+
+COMMAND = [:move, :mark, :turn_right, :turn_left].freeze
+
+ COMMAND.each do |command_name|
+ define_method command_name do | *arguments |
+ @instructions << [command_name, *arguments]
+ end
+ end
+
+def self.draw
+ turtle = Turtle.new position
+ turtle.instance_eval &commands
+ turtle.commands
+ case commands
+ when 'move' then puts '1'
+ when 'mark' then puts '4'
+ when 'turn_right' then puts '2'
+ when 'turn_left' then puts '3'
+ end
+end
+
+end
+
+class Canvas
+ attr_reader :canvas
+
+ def initialize(canvas)
+ @canvas = canvas
+ end
+
+class HTML
+ attr_reader :pixels
+
+ def initialize(pixels)
+ @pixels = pixels
+ end
+
+ def set_values(width, height)
+ @pixels[[width, height]] = true
+ end
+
+TEMPLATE = '<!DOCTYPE html>
+<html>
+<head>
+ <title>Turtle graphics</title>
+
+ <style>
+ table {
+ border-spacing: 0;
+ }
+
+ tr {
+ padding: 0;
+ }
+
+ td {
+ width: 5px;
+ height: 5px;
+
+ background-color: black;
+ padding: 0;
+ }
+ </style>
+</head>
+<body>
+ <table>
+ <tr>
+ <td style="opacity: 1.00"></td>
+ <td style="opacity: 1.00"></td>
+ <td style="opacity: 0.00"></td>
+ </tr>
+ <tr>
+ <td style="opacity: 0.00"></td>
+ <td style="opacity: 1.00"></td>
+ <td style="opacity: 1.00"></td>
+ </tr>
+ <tr>
+ <td style="opacity: 0.00"></td>
+ <td style="opacity: 0.00"></td>
+ <td style="opacity: 0.00"></td>
+ </tr>
+ </table>
+</body>
+</html>'.freeze
+
+def render
+ TEMPLATE % super
+end
+
+end
+end
+end