spec/lib/sqed/boundary_finder_spec.rb in sqed-0.0.4 vs spec/lib/sqed/boundary_finder_spec.rb in sqed-0.1.0

- old
+ new

@@ -102,7 +102,95 @@ specify 'returns nil if no count is greater than samples taken' do expect( Sqed::BoundaryFinder.frequency_stats(i, 15)).to eq(nil) end end - + + context 'offset boundaries from crossy_black_line_specimen image ' do + before(:all) { + @s = Sqed.new(image: ImageHelpers.crossy_black_line_specimen, pattern: :offset_cross, boundary_color: :black) + @s.crop_image + @offset_boundaries = @s.boundaries.offset(@s.stage_boundary) + true + } + + ##**** actually fails (?!) + specify "offset and size should match internal found areas " do + sbx = @s.stage_boundary.x_for(0) + sby = @s.stage_boundary.y_for(0) + + sl = @s.boundaries.coordinates.length # may be convenient to clone this model for other than 4 boundaries found + expect(sl).to eq(4) #for offset cross pattern and valid image + expect(@s.boundaries.complete).to be(true) + expect(@offset_boundaries.complete).to be(true) + (0..sl - 1).each do |i| + # check all the x/y + expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx) + expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby) + + # check all width/heights + expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i)) + expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i)) + end + end + end + + context 'offset boundaries from black_green_line_specimen image ' do + before(:all) { + @s = Sqed.new(image: ImageHelpers.black_stage_green_line_specimen, pattern: :offset_cross) + @s.crop_image + @offset_boundaries = @s.boundaries.offset(@s.stage_boundary) + true + } + + specify "offset and size should match internal found areas " do + sbx = @s.stage_boundary.x_for(0) + sby = @s.stage_boundary.y_for(0) + + sl = @s.boundaries.coordinates.count # may be convenient to clone this model for other than 4 boundaries found + expect(sl).to eq(4) #for offset cross pattern and valid image + expect(@s.boundaries.complete).to be(true) + expect(@offset_boundaries.complete).to be(true) + (0..sl - 1).each do |i| + # check all the x/y + expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx) + expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby) + + # check all width/heights + expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i)) + expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i)) + end + end + end + + context 'offset boundaries from original red_line image ' do + before(:all) { + @s = Sqed.new(image: ImageHelpers.offset_cross_red, pattern: :right_t, boundary_color: :red) + @s.crop_image + @offset_boundaries = @s.boundaries.offset(@s.stage_boundary) + } + + specify "offset and size should match internal found areas " do + sbx = @s.stage_boundary.x_for(0) # only a single boundary + sby = @s.stage_boundary.y_for(0) + pct = 0.02 + + sl = @s.boundaries.coordinates.count + expect(sl).to eq(3) + expect(@s.boundaries.complete).to be(true) + expect(@offset_boundaries.complete).to be(true) + expect(@s.stage_boundary.width_for(0)).to be_within(pct*800).of(800) + expect(@s.stage_boundary.height_for(0)).to be_within(pct*600).of(600) + (0..sl - 1).each do |i| + # check all the x/y + expect(@offset_boundaries.x_for(i)).to eq(@s.boundaries.x_for(i) + sbx) + expect(@offset_boundaries.y_for(i)).to eq(@s.boundaries.y_for(i) + sby) + + # check all width/heights + expect(@offset_boundaries.width_for(i)).to eq(@s.boundaries.width_for(i)) + expect(@offset_boundaries.height_for(i)).to eq(@s.boundaries.height_for(i)) + end + end + end + + end