require 'spec_helper' module Mork describe Grid do context 'default grid', focus: true do before(:all) do @grid = Grid.new @grid.set_page_size 1601, 2281 # the size of sample01.jpg end describe '#max_questions' do it 'returns the maximum number of questions in a sheet' do @grid.max_questions.should == 120 end end describe '#max_choices_per_question' do it 'returns the maximum number of choice cells per question' do @grid.max_choices_per_question.should == 5 end end describe '#code_bits' do it 'returns the number of bits used to define the form code' do @grid.code_bits.should == 40 end it 'returns an integer' do @grid.code_bits.should be_a Fixnum end end describe '#rm_search_area' do context 'on the first iteration' do it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :tl reg_mark corner' do c = @grid.rm_search_area :tl, 0 c.should == { x: 23, y: 23, w: 76, h: 77 } end it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :tr reg_mark corner' do c = @grid.rm_search_area :tr, 0 c.should == { x: 1502, y: 23, w: 76, h: 77 } end it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :br reg_mark corner' do c = @grid.rm_search_area :br, 0 c.should == { x: 1502, y: 2181, w: 76, h: 77 } end it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :bl reg_mark corner' do c = @grid.rm_search_area :bl, 0 c.should == { x: 23, y: 2181, w: 76, h: 77 } end end context 'on the third iteration' do it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :tl reg_mark corner' do c = @grid.rm_search_area :tl, 2 c.should == { x: 23, y: 23, w: 114, h: 115 } end it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :tr reg_mark corner' do c = @grid.rm_search_area :tr, 2 c.should == { x: 1464, y: 23, w: 114, h: 115 } end it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :br reg_mark corner' do c = @grid.rm_search_area :br, 2 c.should == { x: 1464, y: 2143, w: 114, h: 115 } end it 'returns an {:x, :y, :w, :h} hash of coordinates in pixels for the :bl reg_mark corner' do c = @grid.rm_search_area :bl, 2 c.should == { x: 23, y: 2143, w: 114, h: 115 } end end end describe '#rm_edgy_x' do it 'returns the minimum acceptable number of pixels from the regmark center to the edge of the rm_search_area' do @grid.rm_edgy_x.should == 24 end it 'returns an integer' do @grid.rm_edgy_x.should be_a Fixnum end end describe '#rm_edgy_y' do it 'returns the minimum acceptable number of pixels from the regmark center to the edge of the rm_search_area' do @grid.rm_edgy_y.should == 24 end it 'returns an integer' do @grid.rm_edgy_y.should be_a Fixnum end end describe '#rm_max_search_area_side' do it 'returns the maximum extent of the regmark search area, 1/4 of the raw image horizontal pixels' do @grid.rm_max_search_area_side.should == 400 end it 'returns an integer' do @grid.rm_max_search_area_side.should be_a Fixnum end end describe '#choice_cell_area' do it 'returns the coordinates of the first choice cell' do @grid.choice_cell_area(0,0).should == {x: 63, y: 436, w: 51, h: 41} end it 'returns the coordinates of the last choice cell' do @grid.choice_cell_area(119,4).should == {x: 1538, y: 2108, w: 51, h: 41} end end describe '#ctrl_area_dark' do it 'returns the coordinates of the control cell used to set the darkened threshold' do @grid.ctrl_area_dark.should == {:x=>1479, :y=>329, :w=>51, :h=>41} end end describe '#ctrl_area_light' do it 'returns the coordinates of the control cell used to set the darkened threshold' do @grid.ctrl_area_light.should == {:x=>1538, :y=>329, :w=>51, :h=>41} end end describe '#cal_area_white' do it 'returns the coordinates of the white area used for code calibration' do @grid.cal_area_white.should == {:x=>93, :y=>2260, :w=>25, :h=>21} end end describe '#cal_area_black' do it 'returns the coordinates of the code calibration bar' do @grid.cal_area_black.should == {:x=>126, :y=>2260, :w=>25, :h=>21} end end describe '#code_bit_area' do it 'returns the coordinates of the first code bit area' do @grid.code_bit_area(0).should == {:x=>160, :y=>2260, :w=>25, :h=>21} end it 'returns the coordinates of the last code bit area' do @grid.code_bit_area(39).should == {:x=>1475, :y=>2260, :w=>25, :h=>21} end it 'fails if an invalid code bit is requested' do lambda { @grid.code_bit_area(40) }.should raise_error end end end # describe "#cell_x" do # context "for 1st-column questions" do # it "returns the distance from the registration frame of the left edge of the 1st choice" do # grid.send(:cell_x,0,0).should == 7.5 # end # # it "returns the distance from the registration frame of the left edge of the 2nd choice" do # grid.send(:cell_x,0,1).should == 14.5 # end # end # # context "for 4th-column questions" do # it "returns the distance from the registration frame of the left edge of the 1st choice" do # grid.send(:cell_x,120,0).should == 157.5 # end # # it "returns the distance from the registration frame of the left edge of the 2nd choice" do # grid.send(:cell_x,120,1).should == 164.5 # end # end # end # # describe "#cell_y" do # it "returns the distance from the registration frame of the top edge of the 1st row of cells" do # grid.send(:cell_y,0).should == 33.5 # end # # it "returns the distance from the registration frame of the 40th row of cells" do # grid.send(:cell_y,39).should == 267.5 # end # end end end # describe "#question_area" do # before(:each) do # grid.reg_marks(@image) # end # it "returns a hash" do # grid.question_area(1).should be_an_instance_of(Hash) # end # # it "returns the location in pixels of the first question patch" do # c = grid.question_area(1) # c[:x].should be_within(4).of(90) # c[:y].should be_within(4).of(388) # end # it "returns the location in pixels of the 40th question patch" do # c = grid.question_area(40) # c[:x].should be_within(4).of(90) # c[:y].should be_within(4).of(3120) # end # # it "returns the location in pixels of the 121th question patch" do # c = grid.question_area(121) # c[:x].should be_within(4).of(1887) # c[:y].should be_within(4).of(388) # end # # it "returns the location in pixels of the last question patch" do # c = grid.question_area(160) # c[:x].should be_within(4).of(1887) # c[:y].should be_within(4).of(3120) # end # end