spec/lib/sqed/boundary_finder_spec.rb in sqed-0.1.2 vs spec/lib/sqed/boundary_finder_spec.rb in sqed-0.1.3
- old
+ new
@@ -5,11 +5,11 @@
specify 'when no image provided, #new raises' do
expect { Sqed::BoundaryFinder.new() }.to raise_error
end
context 'when initiated with an image' do
- let(:b) {Sqed::BoundaryFinder.new(image: ImageHelpers.standard_cross_green, layout: :offset_cross)}
+ let(:b) {Sqed::BoundaryFinder.new(image: ImageHelpers.standard_cross_green, layout: :vertical_offset_cross)}
context 'attributes' do
specify '#img' do
expect(b).to respond_to(:img)
end
@@ -18,81 +18,85 @@
specify '#boundaries' do
expect(b.boundaries.class).to eq(Sqed::Boundaries)
end
end
- context '.color_boundary_finder(image: image, sample_subdivision: 10)' do
- specify 'finds the vertical dividing line in a standard cross, with border still present' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.standard_cross_green)[1]
- expect(center).to be > 492
- expect(center).to be < 504
+ context '.color_boundary_finder(image: image)' do
+ context 'with sample_subdivision_size: 10' do
+ specify 'finds the vertical dividing line in a standard cross, with border still present' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.standard_cross_green, sample_subdivision_size: 10 )[1]
+ expect(center).to be > 492
+ expect(center).to be < 504
+ end
+
+ specify 'finds the vertical dividing line in a right t green cross, with border still present' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.right_t_green, sample_subdivision_size: 10)[1]
+ expect(center).to be > 695
+ expect(center).to be < 705
+ end
end
- specify 'finds the vertical dividing line in a standard cross, with border still present, when more precise' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.standard_cross_green, sample_cutoff_factor: 0.7)[1]
- expect(center).to be > 492
- expect(center).to be < 504
- end
+ context 'with sample_subdivision_size auto set' do
+ specify 'finds the vertical dividing line in a standard cross, with border still present, when more precise' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.standard_cross_green, sample_cutoff_factor: 0.7)[1]
+ expect(center).to be > 492
+ expect(center).to be < 504
+ end
- specify 'finds the vertical dividing line in a right t green cross, with border still present' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.right_t_green)[1]
- expect(center).to be > 695
- expect(center).to be < 705
- end
+ specify 'finds the vertical dividing line a real image, with border still present' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen)[1]
+ expect(center).to be > 2452
+ expect(center).to be < 2495
+ end
- specify 'finds the vertical dividing line a real image, with border still present' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen)[1]
- expect(center).to be > 2452
- expect(center).to be < 2495
- end
+ specify 'finds the vertical dividing line a real image, with border still present, with 10x fewer subsamples' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 100 )[1]
+ expect(center).to be > 2452
+ expect(center).to be < 2495
+ end
- specify 'finds the vertical dividing line a real image, with border still present, with 10x fewer subsamples' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 100 )[1]
- expect(center).to be > 2452
- expect(center).to be < 2495
- end
+ specify 'finds the vertical dividing line a real image, with border still present, with 50x fewer subsamples' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 500 )[1]
+ expect(center).to be > 2452
+ expect(center).to be < 2495
+ end
- specify 'finds the vertical dividing line a real image, with border still present, with 50x fewer subsamples' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 500 )[1]
- expect(center).to be > 2452
- expect(center).to be < 2495
- end
+ specify 'FAILS to find the vertical dividing line a real image, with border still present, with 200x fewer subsamples' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 2000 )
+ expect(center).to be nil
+ end
- specify 'FAILS to find the vertical dividing line a real image, with border still present, with 200x fewer subsamples' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.crossy_green_line_specimen, sample_subdivision_size: 2000 )
- expect(center).to be nil
- end
+ specify 'finds the vertical dividing line another real image, with border still present' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image)[1]
+ expect(center).to be > 2445
+ expect(center).to be < 2495
+ end
- specify 'finds the vertical dividing line another real image, with border still present' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image)[1]
- expect(center).to be > 2445
- expect(center).to be < 2495
- end
+ specify 'finds the vertical dividing line another real image, with border still present, and 20x fewer subsamples' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, sample_subdivision_size: 200)[1]
+ expect(center).to be > 2445
+ expect(center).to be < 2495
+ end
- specify 'finds the vertical dividing line another real image, with border still present, and 20x fewer subsamples' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, sample_subdivision_size: 200)[1]
- expect(center).to be > 2445
- expect(center).to be < 2495
- end
+ specify 'finds the vertical dividing line another real image, with border still present, and 50x fewer subsamples' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, sample_subdivision_size: 500)[1]
+ expect(center).to be > 2445
+ expect(center).to be < 2495
+ end
- specify 'finds the vertical dividing line another real image, with border still present, and 50x fewer subsamples' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, sample_subdivision_size: 500)[1]
- expect(center).to be > 2445
- expect(center).to be < 2495
- end
+ specify 'FAILS to find the vertical dividing line in a standard cross, with border still present, when even more precise' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.standard_cross_green, sample_cutoff_factor: 1)
+ expect(center).to be nil
+ end
- specify 'FAILS to find the vertical dividing line in a standard cross, with border still present, when even more precise' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.standard_cross_green, sample_cutoff_factor: 1)
- expect(center).to be nil
+ specify 'finds the horizontal dividing line another real image, with border still present' do
+ center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, scan: :columns)[1]
+ expect(center).to be > 1282
+ expect(center).to be < 1332
+ end
end
- specify 'finds the horizontal dividing line another real image, with border still present' do
- center = Sqed::BoundaryFinder.color_boundary_finder(image: ImageHelpers.greenline_image, scan: :columns)[1]
- expect(center).to be > 1282
- expect(center).to be < 1332
- end
-
end
context '.frequency_stats(frequency_hash, samples_taken)' do
# i is a Hash of position => count (it is unordered, but constructed ordered here in assignment)
let(:i) { {1 => 1, 2 => 3, 3 => 15, 4 => 14, 5 => 13 }}
@@ -105,11 +109,11 @@
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 = Sqed.new(image: ImageHelpers.crossy_black_line_specimen, pattern: :vertical_offset_cross, boundary_color: :black)
@s.crop_image
@offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
true
}
@@ -134,11 +138,11 @@
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 = Sqed.new(image: ImageHelpers.black_stage_green_line_specimen, pattern: :vertical_offset_cross)
@s.crop_image
@offset_boundaries = @s.boundaries.offset(@s.stage_boundary)
true
}
@@ -162,10 +166,10 @@
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 = Sqed.new(image: ImageHelpers.vertical_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