Георги обнови решението на 17.12.2013 18:09 (преди почти 11 години)
+result.insert(0,type[3])
Към профила на Георги Пурнаров
........FFF..FFF.......F..F.....F.F........FF.FFFF........FFFF...FFFF Failures: 1) Graphics Canvas drawing of shapes and rasterization renders multiple drawn shapes Failure/Error: ascii.should eq rendering(expected) expected: "@@@@@@@@@@@@@@@\n@-------------@\n@-@@@@@@@@@@@-@\n@-@---------@-@\n@-@------@@-@-@\n@-@---@@@---@-@\n@-@-@@------@-@\n@-@---------@-@\n@-@-@@@@----@-@\n@-@-@-------@-@\n@-@---------@-@\n@-@---------@-@\n@-@@@@@@@@@@@-@\n@-------------@\n@@@@@@@@@@@@@@@" got: "@@@@@@@@@@@@@@@\n@-------------@\n@-@@@@@@@@@@@-@\n@-@---------@-@\n@-@-@@------@-@\n@-@---@@@---@-@\n@-@------@--@-@\n@-@-------@-@-@\n@-@-@@@@----@-@\n@-@-@-------@-@\n@-@---------@-@\n@-@---------@-@\n@-@@@@@@@@@@@-@\n@-------------@\n@@@@@@@@@@@@@@@" (compared using ==) Diff: @@ -2,10 +2,10 @@ @-------------@ @-@@@@@@@@@@@-@ @-@---------@-@ -@-@------@@-@-@ -@-@---@@@---@-@ @-@-@@------@-@ -@-@---------@-@ +@-@---@@@---@-@ +@-@------@--@-@ +@-@-------@-@-@ @-@-@@@@----@-@ @-@-@-------@-@ @-@---------@-@ # /tmp/d20131223-4637-ndeiyb/spec.rb:624:in `check_rendering_of' # /tmp/d20131223-4637-ndeiyb/spec.rb:211: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)>' 2) Graphics Canvas drawing of shapes and rasterization of points works for a single one Failure/Error: canvas.pixel_at?(2, 4).should be_true expected: true value got: false # /tmp/d20131223-4637-ndeiyb/spec.rb:48: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) Graphics Canvas drawing of shapes and rasterization of points works for multiple ones Failure/Error: canvas.set_pixel 4, 4 NoMethodError: undefined method `[]=' for nil:NilClass # /tmp/d20131223-4637-ndeiyb/solution.rb:13:in `set_pixel' # /tmp/d20131223-4637-ndeiyb/spec.rb:57: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 lines with a small slope Failure/Error: canvas.draw make_line(make_point(1, 1), make_point(8, 3)) NoMethodError: undefined method `[]=' for nil:NilClass # /tmp/d20131223-4637-ndeiyb/solution.rb:55:in `block in draw_line_x' # /tmp/d20131223-4637-ndeiyb/solution.rb:54:in `upto' # /tmp/d20131223-4637-ndeiyb/solution.rb:54:in `each' # /tmp/d20131223-4637-ndeiyb/solution.rb:54:in `draw_line_x' # /tmp/d20131223-4637-ndeiyb/solution.rb:35:in `draw_line' # /tmp/d20131223-4637-ndeiyb/solution.rb:24:in `draw' # /tmp/d20131223-4637-ndeiyb/spec.rb:98: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 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: "----------\n-@--------\n-@--------\n--@-------\n---@------\n---@------\n---@------\n----@-----\n-----@----\n----------" (compared using ==) Diff: @@ -2,10 +2,10 @@ -@-------- -@-------- --@------- ---@------- ---@------- ---@------- ---@------ ---@------ +---@------ +----@----- +-----@---- ---------- # /tmp/d20131223-4637-ndeiyb/spec.rb:624:in `check_rendering_of' # /tmp/d20131223-4637-ndeiyb/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)>' 6) Graphics Canvas drawing of shapes and rasterization of lines works with multiple lines Failure/Error: canvas.draw make_line(make_point(1, 1), make_point(8, 3)) NoMethodError: undefined method `[]=' for nil:NilClass # /tmp/d20131223-4637-ndeiyb/solution.rb:55:in `block in draw_line_x' # /tmp/d20131223-4637-ndeiyb/solution.rb:54:in `upto' # /tmp/d20131223-4637-ndeiyb/solution.rb:54:in `each' # /tmp/d20131223-4637-ndeiyb/solution.rb:54:in `draw_line_x' # /tmp/d20131223-4637-ndeiyb/solution.rb:35:in `draw_line' # /tmp/d20131223-4637-ndeiyb/solution.rb:24:in `draw' # /tmp/d20131223-4637-ndeiyb/spec.rb:129: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 Renderers Ascii renders simple canvases Failure/Error: canvas.set_pixel 3, 2 NoMethodError: undefined method `[]=' for nil:NilClass # /tmp/d20131223-4637-ndeiyb/solution.rb:13:in `set_pixel' # /tmp/d20131223-4637-ndeiyb/spec.rb:254: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)>' 8) Graphics Renderers Html renders simple canvases Failure/Error: html_rendering_of(canvas).should eq [ expected: "<i></i><i></i><i></i><i></i><br><i></i><b></b><i></i><i></i><br><i></i><b></b><i></i><i></i>" got: "<i></i><i></i><i></i><i></i><br><i></i><b></b><b></b><i></i><br><i></i><i></i><i></i><i></i><br" (compared using ==) # /tmp/d20131223-4637-ndeiyb/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)>' 9) 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-ndeiyb/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)>' 10) Graphics shapes Point comparison for equality works for eql? as well Failure/Error: a1.should eql a2 expected: #<Graphics::Point:0xba03fa88 @x=4, @y=5> got: #<Graphics::Point:0xba03fb00 @x=4, @y=5> (compared using eql?) Diff: @@ -1,2 +1,2 @@ -#<Graphics::Point:0xba03fa88 @x=4, @y=5> +#<Graphics::Point:0xba03fb00 @x=4, @y=5> # /tmp/d20131223-4637-ndeiyb/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)>' 11) 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-ndeiyb/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)>' 12) 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-ndeiyb/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)>' 13) 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-ndeiyb/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)>' 14) 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-ndeiyb/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)>' 15) 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-ndeiyb/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)>' 16) Graphics shapes Line comparison for equality works with eql? as well Failure/Error: a.should eql b expected: #<Graphics::Line:0xba0145e0 @point_1=#<Graphics::Point:0xba01475c @x=1, @y=1>, @point_2=#<Graphics::Point:0xba0146e4 @x=10, @y=14>> got: #<Graphics::Line:0xba0147c0 @point_1=#<Graphics::Point:0xba014874 @x=1, @y=1>, @point_2=#<Graphics::Point:0xba014838 @x=10, @y=14>> (compared using eql?) Diff: @@ -1,4 +1,4 @@ -#<Graphics::Line:0xba0145e0 - @point_1=#<Graphics::Point:0xba01475c @x=1, @y=1>, - @point_2=#<Graphics::Point:0xba0146e4 @x=10, @y=14>> +#<Graphics::Line:0xba0147c0 + @point_1=#<Graphics::Point:0xba014874 @x=1, @y=1>, + @point_2=#<Graphics::Point:0xba014838 @x=10, @y=14>> # /tmp/d20131223-4637-ndeiyb/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)>' 17) Graphics shapes Rectangle comparison for equality is true if rectangle points are the same Failure/Error: (a == b).should be_true expected: true value got: false # /tmp/d20131223-4637-ndeiyb/spec.rb:526: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)>' 18) Graphics shapes Rectangle comparison for equality is true if rectangle points are the same, even if swapped Failure/Error: (a == b).should be_true expected: true value got: false # /tmp/d20131223-4637-ndeiyb/spec.rb:533: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)>' 19) Graphics shapes Rectangle comparison for equality is true for rectangles defined with different diagonal corners Failure/Error: (a == b).should be_true expected: true value got: false # /tmp/d20131223-4637-ndeiyb/spec.rb:540: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)>' 20) Graphics shapes Rectangle comparison for equality works with eql? as well Failure/Error: a.should eql b expected: #<Graphics::Rectangle:0xb9fd0840 @point_1=#<Graphics::Point:0xb9fd08e0 @x=1, @y=1>, @point_2=#<Graphics::Point:0xb9fd087c @x=10, @y=14>> got: #<Graphics::Rectangle:0xb9fd0930 @point_1=#<Graphics::Point:0xb9fd0994 @x=1, @y=1>, @point_2=#<Graphics::Point:0xb9fd0958 @x=10, @y=14>> (compared using eql?) Diff: @@ -1,4 +1,4 @@ -#<Graphics::Rectangle:0xb9fd0840 - @point_1=#<Graphics::Point:0xb9fd08e0 @x=1, @y=1>, - @point_2=#<Graphics::Point:0xb9fd087c @x=10, @y=14>> +#<Graphics::Rectangle:0xb9fd0930 + @point_1=#<Graphics::Point:0xb9fd0994 @x=1, @y=1>, + @point_2=#<Graphics::Point:0xb9fd0958 @x=10, @y=14>> # /tmp/d20131223-4637-ndeiyb/spec.rb:548: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)>' 21) Graphics shapes Rectangle corners top left Failure/Error: rect.top_left.y.should eq 2 expected: 2 got: 4 (compared using ==) # /tmp/d20131223-4637-ndeiyb/spec.rb:578: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)>' 22) Graphics shapes Rectangle corners top right Failure/Error: rect.top_right.y.should eq 4 expected: 4 got: 6 (compared using ==) # /tmp/d20131223-4637-ndeiyb/spec.rb:584: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 Rectangle corners bottom right Failure/Error: rect.bottom_right.y.should eq 4 expected: 4 got: 2 (compared using ==) # /tmp/d20131223-4637-ndeiyb/spec.rb:590: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 Rectangle corners bottom left Failure/Error: rect.bottom_left.y.should eq 8 expected: 8 got: 4 (compared using ==) # /tmp/d20131223-4637-ndeiyb/spec.rb:596: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.09677 seconds 69 examples, 24 failures Failed examples: rspec /tmp/d20131223-4637-ndeiyb/spec.rb:203 # Graphics Canvas drawing of shapes and rasterization renders multiple drawn shapes rspec /tmp/d20131223-4637-ndeiyb/spec.rb:45 # Graphics Canvas drawing of shapes and rasterization of points works for a single one rspec /tmp/d20131223-4637-ndeiyb/spec.rb:51 # Graphics Canvas drawing of shapes and rasterization of points works for multiple ones rspec /tmp/d20131223-4637-ndeiyb/spec.rb:96 # Graphics Canvas drawing of shapes and rasterization of lines works with lines with a small slope rspec /tmp/d20131223-4637-ndeiyb/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-ndeiyb/spec.rb:127 # Graphics Canvas drawing of shapes and rasterization of lines works with multiple lines rspec /tmp/d20131223-4637-ndeiyb/spec.rb:252 # Graphics Renderers Ascii renders simple canvases rspec /tmp/d20131223-4637-ndeiyb/spec.rb:287 # Graphics Renderers Html renders simple canvases rspec /tmp/d20131223-4637-ndeiyb/spec.rb:347 # Graphics shapes Point comparison for equality is true if coordinates are the same rspec /tmp/d20131223-4637-ndeiyb/spec.rb:355 # Graphics shapes Point comparison for equality works for eql? as well rspec /tmp/d20131223-4637-ndeiyb/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-ndeiyb/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-ndeiyb/spec.rb:431 # Graphics shapes Line comparison for equality is true if line ends are the same rspec /tmp/d20131223-4637-ndeiyb/spec.rb:438 # Graphics shapes Line comparison for equality is true if line ends are the same, even if swapped rspec /tmp/d20131223-4637-ndeiyb/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-ndeiyb/spec.rb:452 # Graphics shapes Line comparison for equality works with eql? as well rspec /tmp/d20131223-4637-ndeiyb/spec.rb:522 # Graphics shapes Rectangle comparison for equality is true if rectangle points are the same rspec /tmp/d20131223-4637-ndeiyb/spec.rb:529 # Graphics shapes Rectangle comparison for equality is true if rectangle points are the same, even if swapped rspec /tmp/d20131223-4637-ndeiyb/spec.rb:536 # Graphics shapes Rectangle comparison for equality is true for rectangles defined with different diagonal corners rspec /tmp/d20131223-4637-ndeiyb/spec.rb:543 # Graphics shapes Rectangle comparison for equality works with eql? as well rspec /tmp/d20131223-4637-ndeiyb/spec.rb:575 # Graphics shapes Rectangle corners top left rspec /tmp/d20131223-4637-ndeiyb/spec.rb:581 # Graphics shapes Rectangle corners top right rspec /tmp/d20131223-4637-ndeiyb/spec.rb:587 # Graphics shapes Rectangle corners bottom right rspec /tmp/d20131223-4637-ndeiyb/spec.rb:593 # Graphics shapes Rectangle corners bottom left
Бележки:
draw_line
спокойно може да се казва line
, вместо figure
. По-конкретно е.draw_line
е доста наблъскан и нечетим; ternary операторите не помагат. Помисли дали има начин да подобриш това положение някак. Това важи и за другите методи.draw_line
, draw_line_y
и прочее са публични. Добра идея ли е това? Ако не се ползват отвън, може би не трябва да са част от публичния интерфейс на пано.Html
и Ascii
като кофи за данни. Натовари ги с някаква логика – все пак това е основната идея на ОО-програмирането – да разпределиш различните отговорности между различни обекти. Стреми се всеки обект да отговаря за едно конкретно нещо и само за него. Напълно нормално е да имаш голям брой малки обекти в системата, с тясно специализирани отговорности. В момента, според мен, паното ти има прекалено много логика – да не кажа цялата логика на задачата. За растеризация на обекти, за рендериране на обекти... Опитай да я разпределиш.rendering_panel
– пробвай да го преработиш така, че да ползва map
и join
и да нямаш нужда от променлива тип result
.to_int
не се ползва; замени го с to_i
където ти трябваeql?
.hash
работи. Съветвам те да последваш съвета на условието и да стъпиш на съществуващи имплементации на hash
от други Ruby класове.Line#from
и Line#to
някак :) Същото важи и за Rectangle#from
и to
.hash
. Виж моето решение за справка.Hash
с ключ точка (списък с две числа) и стойност true
ми се струва по-удачно от твоя вариант. Пак, виж аз как съм решил проблема с представянето на пано.private
над методите, които са такива.gsub!
в rendering_panel
метода). Казвали сме го многократно на лекции и сме обяснявали защо.result
е лошо име на променлива (пак в същия метод). Ако ти е трудно да измислиш име, помисли дали това не е знак, че трбява да промениш дизайна някак (в случая може да се ползва map
+ join
и да няма нужда от променливи като result
или gsub!
).Като цяло, имаш нужда да поработиш доста над стила си, спазването на конвенци и именуването на неща. Не си успял да влезеш все още в духа на Ruby. Има какво да се желае и откъм идеите ти за дизайн. Работи над това :)