Решение на Трета задача от Иван Иванов

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

Към профила на Иван Иванов

Резултати

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

Код

module Graphics
class Canvas
attr_accessor :width, :height, :filled_spots
def initialize width, height
@width = width
@height = height
@filled_spots = {}
end
def set_pixel x, y
filled_spots[x] = y
end
def pixel_at? x, y
if filled_spots[x] == y then true else false end
end
def render_as renderer
if renderer.to_s == 'Graphics::Renderers::Ascii'
# Graphics::Canvas::Printers.print_ascii width, height, filled_spots
end
end
def draw figure
if figure.is_a? Point then self.set_pixel figure.x, figure.y end
end
private
class Printers
def self.pixel_at x, y, filled_spots
if filled_spots[x] == y then true else false end
end
# def self.print_ascii width, height, filled_spots
# return_string, rows, cols = "", height - 1, width - 1
# while rows >= 0
# while cols >= 0
# if Graphics::Canvas::Printers.pixel_at cols, rows, filled_spots
# return_string += "*"
# else
# return_string += "-"
# end
# cols -= 1
# end
# cols = width - 1
# unless rows == 0 then return_string += "\n" end
# rows -= 1
# end
# return_string.reverse
# end
end
end
class Renderers
class Ascii
end
end
class Point
attr_accessor :x, :y
def initialize x, y
@x = x
@y = y
end
end
class Line
attr_accessor :from , :to
def initialize from, to
if to.is_a? Point
@from = from
@to = to
end
end
end
end

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

....F...F.FFFFFFFFFFFFFFFFFF...FF.FF....FFFFF.FFFFF.FFFFFFFFFFFFFFFFF

Failures:

  1) Graphics Canvas does not expose setters for the width or height
     Failure/Error: canvas.should_not respond_to :width=
       expected #<Graphics::Canvas:0xb988de0c @width=30, @height=20, @filled_spots={}> not to respond to :width=
     # /tmp/d20131223-4637-kcx0vs/spec.rb:23: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)>'

  2) Graphics Canvas drawing of shapes and rasterization renders multiple drawn shapes
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:205:in `block (4 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) Graphics Canvas drawing of shapes and rasterization of points works for multiple ones
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "@---\n@---\n-@@-\n----"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:59: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) Graphics Canvas drawing of shapes and rasterization of lines works with simple horizontal lines
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "--------\n---@@@@-\n--------"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:73: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) Graphics Canvas drawing of shapes and rasterization of lines works with vertical lines
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "-@------\n-@------\n-@------\n-@------\n-@------\n-@------\n-@------\n--------"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:84: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) Graphics Canvas drawing of shapes and rasterization of lines works with lines with a small slope
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "----------\n-@@-------\n---@@@@---\n-------@@-\n----------"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:100: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) Graphics Canvas drawing of shapes and rasterization of lines works with lines with a significant slope, with swapped ends
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "----------\n-@--------\n-@--------\n--@-------\n--@-------\n--@-------\n--@-------\n---@------\n---@------\n----------"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:113: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) Graphics Canvas drawing of shapes and rasterization of lines works with multiple lines
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "-@--------\n-@@-------\n-@-@@@@---\n-@-----@@-\n----------"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:132: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) Graphics Canvas drawing of shapes and rasterization of lines draws lines with two equal ends as points
     Failure/Error: ascii.should eq rendering(expected)
       
       expected: "---\n-@-\n---"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:624:in `check_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:145: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) Graphics Canvas drawing of shapes and rasterization of rectangles works with simple rects
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:156: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)>'

  11) Graphics Canvas drawing of shapes and rasterization of rectangles works with rects defined with their bottom left and top right points
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:169: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)>'

  12) Graphics Canvas drawing of shapes and rasterization of rectangles works with rects with a zero height as a line
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:182: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)>'

  13) Graphics Canvas drawing of shapes and rasterization of rectangles works with rects with a zero width and height as a single point
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:193: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)>'

  14) Graphics Renderers Ascii renders a grid of the size of the canvas
     Failure/Error: lines = canvas.render_as(ascii).split("\n")
     NoMethodError:
       undefined method `split' for nil:NilClass
     # /tmp/d20131223-4637-kcx0vs/spec.rb:238:in `block (4 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)>'

  15) Graphics Renderers Ascii renders blank canvases
     Failure/Error: canvas.render_as(ascii).should eq rendering('
       
       expected: "----\n----\n----"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:245:in `block (4 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)>'

  16) Graphics Renderers Ascii renders simple canvases
     Failure/Error: canvas.render_as(ascii).should eq rendering('
       
       expected: "@---\n----\n---@"
            got: nil
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:256:in `block (4 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)>'

  17) Graphics Renderers Html returns html
     Failure/Error: let(:html)        { Graphics::Renderers::Html }
     NameError:
       uninitialized constant Graphics::Renderers::Html
     # /tmp/d20131223-4637-kcx0vs/spec.rb:265:in `block (4 levels) in <top (required)>'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:272:in `block (4 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)>'

  18) Graphics Renderers Html renders a grid of the size of the canvas
     Failure/Error: let(:html)        { Graphics::Renderers::Html }
     NameError:
       uninitialized constant Graphics::Renderers::Html
     # /tmp/d20131223-4637-kcx0vs/spec.rb:265:in `block (4 levels) in <top (required)>'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:309:in `html_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:281:in `block (4 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)>'

  19) Graphics Renderers Html renders simple canvases
     Failure/Error: let(:html)        { Graphics::Renderers::Html }
     NameError:
       uninitialized constant Graphics::Renderers::Html
     # /tmp/d20131223-4637-kcx0vs/spec.rb:265:in `block (4 levels) in <top (required)>'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:309:in `html_rendering_of'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:291:in `block (4 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)>'

  20) Graphics Renderers Html returns the same rendering when called twice
     Failure/Error: let(:html)        { Graphics::Renderers::Html }
     NameError:
       uninitialized constant Graphics::Renderers::Html
     # /tmp/d20131223-4637-kcx0vs/spec.rb:265:in `block (4 levels) in <top (required)>'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:302:in `block (4 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)>'

  21) Graphics shapes Point does not allow setting its x and y
     Failure/Error: point.should_not respond_to :x=
       expected #<Graphics::Point:0xb9806ca4 @x=1, @y=2> not to respond to :x=
     # /tmp/d20131223-4637-kcx0vs/spec.rb:337:in `block (4 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)>'

  22) Graphics shapes Point comparison for equality is true if coordinates are the same
     Failure/Error: (a1 == a2).should be_true
       expected: true value
            got: false
     # /tmp/d20131223-4637-kcx0vs/spec.rb:348: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)>'

  23) Graphics shapes Point comparison for equality works for eql? as well
     Failure/Error: a1.should eql a2
       
       expected: #<Graphics::Point:0xb98061b4 @x=4, @y=5>
            got: #<Graphics::Point:0xb980618c @x=4, @y=5>
       
       (compared using eql?)
       
       Diff:
       @@ -1,2 +1,2 @@
       -#<Graphics::Point:0xb98061b4 @x=4, @y=5>
       +#<Graphics::Point:0xb980618c @x=4, @y=5>
     # /tmp/d20131223-4637-kcx0vs/spec.rb:356: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)>'

  24) Graphics shapes Point comparison for equality returns the same hash for the same points
     Failure/Error: a1.hash.should eq a2.hash
       
       expected: -1030604293
            got: 685326791
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:361: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)>'

  25) Graphics shapes Line initialization does not allow setting its from and to
     Failure/Error: line.should_not respond_to :from=
       expected #<Graphics::Line:0xb97dd430 @from=#<Graphics::Point:0xb97dd494 @x=1, @y=5>, @to=#<Graphics::Point:0xb97dd458 @x=25, @y=2>> not to respond to :from=
     # /tmp/d20131223-4637-kcx0vs/spec.rb:390: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)>'

  26) Graphics shapes Line initialization with swapped points puts the leftmost point in the from field
     Failure/Error: inverted_line.from.x.should eq 1
       
       expected: 1
            got: 25
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:402:in `block (6 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)>'

  27) Graphics shapes Line initialization with swapped points puts the rightmost point in the to field
     Failure/Error: inverted_line.to.x.should eq 25
       
       expected: 25
            got: 1
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:407:in `block (6 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)>'

  28) Graphics shapes Line initialization with swapped points puts the top point of vertical lines in the from field
     Failure/Error: vertical_line.from.y.should eq 1
       
       expected: 1
            got: 8
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:413:in `block (6 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)>'

  29) Graphics shapes Line initialization with swapped points puts the bottom point of vertical lines in the to field
     Failure/Error: vertical_line.to.y.should eq 8
       
       expected: 8
            got: 1
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:418:in `block (6 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)>'

  30) Graphics shapes Line comparison for equality is true if line ends are the same
     Failure/Error: (a == b).should be_true
       expected: true value
            got: false
     # /tmp/d20131223-4637-kcx0vs/spec.rb:435: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)>'

  31) Graphics shapes Line comparison for equality is true if line ends are the same, even if swapped
     Failure/Error: (a == b).should be_true
       expected: true value
            got: false
     # /tmp/d20131223-4637-kcx0vs/spec.rb:442: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)>'

  32) Graphics shapes Line comparison for equality is true if line is vertical and the bottom is given first
     Failure/Error: (a == b).should be_true
       expected: true value
            got: false
     # /tmp/d20131223-4637-kcx0vs/spec.rb:449: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)>'

  33) Graphics shapes Line comparison for equality works with eql? as well
     Failure/Error: a.should eql b
       
       expected: #<Graphics::Line:0xb97bee04 @from=#<Graphics::Point:0xb97beea4 @x=1, @y=1>, @to=#<Graphics::Point:0xb97bee68 @x=10, @y=14>>
            got: #<Graphics::Line:0xb97beee0 @from=#<Graphics::Point:0xb97bef44 @x=1, @y=1>, @to=#<Graphics::Point:0xb97bef1c @x=10, @y=14>>
       
       (compared using eql?)
       
       Diff:
       @@ -1,4 +1,4 @@
       -#<Graphics::Line:0xb97bee04
       - @from=#<Graphics::Point:0xb97beea4 @x=1, @y=1>,
       - @to=#<Graphics::Point:0xb97bee68 @x=10, @y=14>>
       +#<Graphics::Line:0xb97beee0
       + @from=#<Graphics::Point:0xb97bef44 @x=1, @y=1>,
       + @to=#<Graphics::Point:0xb97bef1c @x=10, @y=14>>
     # /tmp/d20131223-4637-kcx0vs/spec.rb:457: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)>'

  34) Graphics shapes Line comparison for equality returns the same hash if the lines are the same
     Failure/Error: a.hash.should eq b.hash
       
       expected: 441405537
            got: 852938799
       
       (compared using ==)
     # /tmp/d20131223-4637-kcx0vs/spec.rb:465: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)>'

  35) Graphics shapes Rectangle initialization requires arguments
     Failure/Error: expect { Graphics::Rectangle.new }.to raise_error(ArgumentError)
       expected ArgumentError, got #<NameError: uninitialized constant Graphics::Rectangle> with backtrace:
         # /tmp/d20131223-4637-kcx0vs/spec.rb:480:in `block (6 levels) in <top (required)>'
         # /tmp/d20131223-4637-kcx0vs/spec.rb:480: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)>'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:480: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)>'

  36) Graphics shapes Rectangle initialization can be created from two points
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:484: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)>'

  37) Graphics shapes Rectangle initialization allows accessing its left and right points via getters
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:488: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)>'

  38) Graphics shapes Rectangle initialization does not allow setting its x and y
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:497: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)>'

  39) Graphics shapes Rectangle initialization puts the leftmost point in its left field
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:505: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)>'

  40) Graphics shapes Rectangle comparison for equality is false if any of the points differ
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:516: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)>'

  41) Graphics shapes Rectangle comparison for equality is true if rectangle points are the same
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:523: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)>'

  42) Graphics shapes Rectangle comparison for equality is true if rectangle points are the same, even if swapped
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:530: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)>'

  43) Graphics shapes Rectangle comparison for equality is true for rectangles defined with different diagonal corners
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:537: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)>'

  44) Graphics shapes Rectangle comparison for equality works with eql? as well
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:544: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)>'

  45) Graphics shapes Rectangle comparison for equality returns the same hash if the rectangles are the same
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:553: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)>'

  46) Graphics shapes Rectangle comparison for equality returns the same hash for rectangles defined with different diagonal corners
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:560: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)>'

  47) Graphics shapes Rectangle comparison for equality returns a different hash if the rectangles differ
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:567: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)>'

  48) Graphics shapes Rectangle corners top left
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:576: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)>'

  49) Graphics shapes Rectangle corners top right
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:582: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)>'

  50) Graphics shapes Rectangle corners bottom right
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:588: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)>'

  51) Graphics shapes Rectangle corners bottom left
     Failure/Error: Graphics::Rectangle.new(*args)
     NameError:
       uninitialized constant Graphics::Rectangle
     # /tmp/d20131223-4637-kcx0vs/spec.rb:615:in `make_rectangle'
     # /tmp/d20131223-4637-kcx0vs/spec.rb:594: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)>'

Finished in 0.09481 seconds
69 examples, 51 failures

Failed examples:

rspec /tmp/d20131223-4637-kcx0vs/spec.rb:22 # Graphics Canvas does not expose setters for the width or height
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:203 # Graphics Canvas drawing of shapes and rasterization renders multiple drawn shapes
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:51 # Graphics Canvas drawing of shapes and rasterization of points works for multiple ones
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:69 # Graphics Canvas drawing of shapes and rasterization of lines works with simple horizontal lines
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:80 # Graphics Canvas drawing of shapes and rasterization of lines works with vertical lines
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:96 # Graphics Canvas drawing of shapes and rasterization of lines works with lines with a small slope
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:109 # Graphics Canvas drawing of shapes and rasterization of lines works with lines with a significant slope, with swapped ends
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:127 # Graphics Canvas drawing of shapes and rasterization of lines works with multiple lines
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:141 # Graphics Canvas drawing of shapes and rasterization of lines draws lines with two equal ends as points
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:154 # Graphics Canvas drawing of shapes and rasterization of rectangles works with simple rects
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:167 # Graphics Canvas drawing of shapes and rasterization of rectangles works with rects defined with their bottom left and top right points
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:180 # Graphics Canvas drawing of shapes and rasterization of rectangles works with rects with a zero height as a line
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:191 # Graphics Canvas drawing of shapes and rasterization of rectangles works with rects with a zero width and height as a single point
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:237 # Graphics Renderers Ascii renders a grid of the size of the canvas
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:244 # Graphics Renderers Ascii renders blank canvases
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:252 # Graphics Renderers Ascii renders simple canvases
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:271 # Graphics Renderers Html returns html
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:280 # Graphics Renderers Html renders a grid of the size of the canvas
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:287 # Graphics Renderers Html renders simple canvases
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:298 # Graphics Renderers Html returns the same rendering when called twice
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:335 # Graphics shapes Point does not allow setting its x and y
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:347 # Graphics shapes Point comparison for equality is true if coordinates are the same
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:355 # Graphics shapes Point comparison for equality works for eql? as well
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:360 # Graphics shapes Point comparison for equality returns the same hash for the same points
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:389 # Graphics shapes Line initialization does not allow setting its from and to
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:401 # Graphics shapes Line initialization with swapped points puts the leftmost point in the from field
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:406 # Graphics shapes Line initialization with swapped points puts the rightmost point in the to field
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:411 # Graphics shapes Line initialization with swapped points puts the top point of vertical lines in the from field
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:416 # Graphics shapes Line initialization with swapped points puts the bottom point of vertical lines in the to field
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:431 # Graphics shapes Line comparison for equality is true if line ends are the same
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:438 # Graphics shapes Line comparison for equality is true if line ends are the same, even if swapped
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:445 # Graphics shapes Line comparison for equality is true if line is vertical and the bottom is given first
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:452 # Graphics shapes Line comparison for equality works with eql? as well
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:461 # Graphics shapes Line comparison for equality returns the same hash if the lines are the same
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:479 # Graphics shapes Rectangle initialization requires arguments
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:483 # Graphics shapes Rectangle initialization can be created from two points
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:487 # Graphics shapes Rectangle initialization allows accessing its left and right points via getters
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:496 # Graphics shapes Rectangle initialization does not allow setting its x and y
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:504 # Graphics shapes Rectangle initialization puts the leftmost point in its left field
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:515 # Graphics shapes Rectangle comparison for equality is false if any of the points differ
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:522 # Graphics shapes Rectangle comparison for equality is true if rectangle points are the same
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:529 # Graphics shapes Rectangle comparison for equality is true if rectangle points are the same, even if swapped
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:536 # Graphics shapes Rectangle comparison for equality is true for rectangles defined with different diagonal corners
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:543 # Graphics shapes Rectangle comparison for equality works with eql? as well
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:552 # Graphics shapes Rectangle comparison for equality returns the same hash if the rectangles are the same
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:559 # Graphics shapes Rectangle comparison for equality returns the same hash for rectangles defined with different diagonal corners
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:566 # Graphics shapes Rectangle comparison for equality returns a different hash if the rectangles differ
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:575 # Graphics shapes Rectangle corners top left
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:581 # Graphics shapes Rectangle corners top right
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:587 # Graphics shapes Rectangle corners bottom right
rspec /tmp/d20131223-4637-kcx0vs/spec.rb:593 # Graphics shapes Rectangle corners bottom left

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

Иван обнови решението на 22.12.2013 21:50 (преди почти 11 години)

+module Graphics
+ class Canvas
+ attr_accessor :width, :height, :filled_spots
+
+ def initialize width, height
+ @width = width
+ @height = height
+ @filled_spots = {}
+ end
+
+ def set_pixel x, y
+ filled_spots[x] = y
+ end
+
+ def pixel_at? x, y
+ if filled_spots[x] == y then true else false end
+ end
+
+ def render_as renderer
+ if renderer.to_s == 'Graphics::Renderers::Ascii'
+ # Graphics::Canvas::Printers.print_ascii width, height, filled_spots
+ end
+ end
+
+ def draw figure
+ if figure.is_a? Point then self.set_pixel figure.x, figure.y end
+ end
+
+ private
+
+ class Printers
+ def self.pixel_at x, y, filled_spots
+ if filled_spots[x] == y then true else false end
+ end
+
+ # def self.print_ascii width, height, filled_spots
+ # return_string, rows, cols = "", height - 1, width - 1
+
+ # while rows >= 0
+ # while cols >= 0
+ # if Graphics::Canvas::Printers.pixel_at cols, rows, filled_spots
+ # return_string += "*"
+ # else
+ # return_string += "-"
+ # end
+ # cols -= 1
+ # end
+
+ # cols = width - 1
+ # unless rows == 0 then return_string += "\n" end
+ # rows -= 1
+ # end
+
+ # return_string.reverse
+ # end
+ end
+
+ end
+
+ class Renderers
+ class Ascii
+ end
+ end
+
+ class Point
+ attr_accessor :x, :y
+
+ def initialize x, y
+ @x = x
+ @y = y
+ end
+ end
+
+ class Line
+ attr_accessor :from , :to
+
+ def initialize from, to
+ if to.is_a? Point
+ @from = from
+ @to = to
+ end
+ end
+ end
+end