require 'spec_helper' module Mork describe Sheet do context 'highlighting' do # since these specs change the @crop, they must be run in isolation # with the Sheet rebuilt each time, even though it is time consuming! let(:sheet) { Sheet.new('spec/samples/sample01.jpg') } it "should highlight all cells" do sheet.highlight_all sheet.write 'tmp/all_highlights.jpg' end it "should highlight marked cells" do sheet.highlight sheet.write 'tmp/highlights.jpg' end it "should highlight the dark calibration bit" do sheet.highlight_dark_calibration_bit sheet.write "tmp/dark_code_bit.jpg" end it "should highlight the light calibration bit" do sheet.highlight_light_calibration_bit sheet.write "tmp/light_code_bit.jpg" end end context "a nicely printed and scanned sheet" do before(:all) do @sheet = Sheet.new('spec/samples/sample01.jpg', Grid.new('spec/samples/grid01.yml')) end describe "#marked?" do it "should return true for some darkened choices" do @sheet.marked?(0,0).should be_truthy @sheet.marked?(1,1).should be_truthy @sheet.marked?(2,2).should be_truthy end it "should return false for some blank choices" do @sheet.marked?(0,1).should be_falsy @sheet.marked?(1,0).should be_falsy @sheet.marked?(2,3).should be_falsy end it "prints the average whiteness of the first 40 sets of choices" do 40.times do |q| t = (0..4).collect do |c| @sheet.send(:shade_of, q, c).round end puts "#{q+1}: #{t.join(" ")}" end end end describe "#mark_array" do it "should return an array of marked choices for each of the first 5 questions" do @sheet.mark_array(5).should == [[0], [1], [2], [3], [4]] end it "should return an array of marked choices for the specified question set" do @sheet.mark_array([0, 1, 15, 16, 31, 7, 26]).should == [[0], [1], [0], [1], [], [1, 3], []] end it "should return an array of @grid.max_questions length if called without arguments" do @sheet.mark_array.length.should == 120 end end describe "#mark_logical_array" do it "should return an array of booleans for each of the first questions" do @sheet.mark_logical_array(5).should == [ [true, false, false, false, false], [false, true, false, false, false], [false, false, true, false, false], [false, false, false, true, false], [false, false, false, false, true], ] end end describe "codes" do it "should read the bit string as all ones" do @sheet.code_string.should == '1111111111111111111111111111111111111111' @sheet.code.should == 1099511627775 end it 'should read another bit string' do code_string = '0000000000000000000000000010000110100000' s2 = Sheet.new('spec/samples/sample02.jpg') s2.code_string.should == code_string s2.code.should == 8608 s2.highlight_code s2.write 'tmp/code_bits.jpg' end end end context "a faded, b&w, distorted sheet" do before(:all) do @sheet = Sheet.new('spec/samples/sample03.jpg') end it "should return the correct code" do @sheet.code.should == 8608 end it "should return the darkened choices" do @sheet.mark_array(16).should == [[3],[3],[4],[0],[4],[4],[0],[1],[4],[0],[],[2,3],[0],[0,1,2,3,4],[1],[]] end end # context "multi-page pdf" do # before(:all) do # @mlist = MimageList.new('spec/samples/two_pages.pdf') # end # # describe "reading the codes" do # it "should read the right code for the first page" do # s = Sheet.new(@mlist[0], Grid.new) # s.code.should == 18446744073709551615 # end # it "should read the right code for the second page" do # s = Sheet.new(@mlist[1], Grid.new) # s.code.should == 283764283738 # end # end # # describe "getting the answers" do # it "should read the correct choices for the first page" do # s = Sheet.new(@mlist[0], Grid.new) # s.marked?( 0, 0).should be_truthy # s.marked?( 0, 1).should be_falsy # s.marked?(15, 3).should be_falsy # s.marked?(15, 4).should be_truthy # end # # it "should read the correct choices for the second page" do # s = Sheet.new(@mlist[1], Grid.new) # s.mark_array(15).should == [[0], [1], [2], [3], [4], [0], [1], [2, 3], [4], [1, 2, 3], [0], [1], [2], [3], [4]] # end # end # end end end