require 'spec_helper' module Mork describe Sheet do context "describing marked choices" 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 a darkened choice" do @sheet.marked?(0,0).should be_true end it "should highlight and show" do @sheet.highlight_all @sheet.write 'tmp/all_highlights.jpg' end it "should return false for a blank choice" do @sheet.marked?(0,1).should be_false 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]).should == [[0], [1], [0], [1], []] end it "should return an array of @grid.max_questions length if called without arguments" do @sheet.mark_array.length.should == 160 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 end context "describing sheet codes" do before(:all) do @smp = sample_img(:code_sample) @cshe = Sheet.new(@smp.filename, Grid.new) end # describe "#dark_code_bit_shade" do # it "should be less than a certain amount" do # v = @cshe.dark_code_bit_shade # v.should < @cshe.send(:dark_threshold) # end # end # # describe "#light_code_bit_shade" do # it "should be more than a certain amount" do # v = @cshe.light_code_bit_shade # v.should > @cshe.send(:dark_threshold) # end # # end describe "#code_string" do it "should read the bit string" do @cshe.code_string.should == @smp.code_string end end describe "#code" do it "should read the bit string and return the integer code" do @cshe.code.should == @smp.code_int end end end context "highlighting stuff" do it "should highlight all high bits in red" do smp = sample_img(:code_sample) s = Sheet.new(smp.filename, Grid.new) 64.times do |i| if smp.code_int[i] == 1 s.highlight_code_bit i end end s.write "tmp/bits.pdf" end it "should highlight the dark calibration bit" do fn = sample_img(:code_sample).filename s = Sheet.new(fn, Grid.new) s.highlight_dark_calibration_bit s.write "tmp/dark_bit.pdf" end it "should highlight the light calibration bit" do fn = sample_img(:code_sample).filename s = Sheet.new(fn, Grid.new) s.highlight_light_calibration_bit s.write "tmp/light_bit.pdf" end end context "faded, b&w sheet" do before(:all) do @smp = sample_img(:bw_faded_sample) @sheet = Sheet.new(@smp.filename, Grid.new) end it "should return the correct code" do @sheet.code.should == @smp.code_int end it "should return the darkened choices" do @sheet.mark_array(12).should == [[2], [3], [4], [0], [1], [2], [0,4], [], [3], [1], [], []] end end context "multi-page pdf" do before(:all) do @smp = sample_img(:two_pages) @mlist = MimageList.new(@smp.filename) 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_true s.marked?( 0, 1).should be_false s.marked?(15, 3).should be_false s.marked?(15, 4).should be_true 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