diff --git a/test/fixtures/sprites/public/images/image_row/large.png b/test/fixtures/sprites/public/images/image_row/large.png new file mode 100644 index 00000000..f86cca9b Binary files /dev/null and b/test/fixtures/sprites/public/images/image_row/large.png differ diff --git a/test/fixtures/sprites/public/images/image_row/large_square.png b/test/fixtures/sprites/public/images/image_row/large_square.png new file mode 100644 index 00000000..b99cf980 Binary files /dev/null and b/test/fixtures/sprites/public/images/image_row/large_square.png differ diff --git a/test/fixtures/sprites/public/images/image_row/medium.png b/test/fixtures/sprites/public/images/image_row/medium.png new file mode 100644 index 00000000..faf62a6d Binary files /dev/null and b/test/fixtures/sprites/public/images/image_row/medium.png differ diff --git a/test/fixtures/sprites/public/images/image_row/small.png b/test/fixtures/sprites/public/images/image_row/small.png new file mode 100644 index 00000000..d8e52311 Binary files /dev/null and b/test/fixtures/sprites/public/images/image_row/small.png differ diff --git a/test/fixtures/sprites/public/images/image_row/tall.png b/test/fixtures/sprites/public/images/image_row/tall.png new file mode 100644 index 00000000..ef422eff Binary files /dev/null and b/test/fixtures/sprites/public/images/image_row/tall.png differ diff --git a/test/units/sprites/image_row_test.rb b/test/units/sprites/image_row_test.rb new file mode 100644 index 00000000..4c92b88a --- /dev/null +++ b/test/units/sprites/image_row_test.rb @@ -0,0 +1,57 @@ +require 'test_helper' + +class ImageRowTest < Test::Unit::TestCase + include SpriteHelper + def setup + create_sprite_temp + file = StringIO.new("images_path = #{@images_src_path.inspect}\n") + Compass.add_configuration(file, "sprite_config") + @filenames = %w(large.png large_square.png medium.png tall.png small.png) + @image_files = Dir["#{@images_src_path}/image_row/*.png"].sort + @images = @image_files.map do |img| + img.gsub!("#{@images_src_path}/", '') + Compass::SassExtensions::Sprites::Image.new(nil, img, {}) + end + image_row(1000) + end + + def teardown + clean_up_sprites + end + + def image_row(max) + @image_row = Compass::SassExtensions::Sprites::ImageRow.new(max) + end + + def populate_row + @images.each do |image| + assert @image_row.add(image) + end + end + + it "should return false if image will not fit in row" do + image_row(100) + img = Compass::SassExtensions::Sprites::Image.new(nil, File.join('image_row', 'large.png'), {}) + assert !@image_row.add(img) + end + + it "should have 5 images" do + populate_row + assert_equal 5, @image_row.images.size + end + + it "should return max image width" do + populate_row + assert_equal 400, @image_row.width + end + + it "should return max image height" do + populate_row + assert_equal 40, @image_row.height + end + + it "should have an efficiency rating" do + populate_row + assert_equal 1 - (580.0 / 1000.0), @image_row.efficiency + end +end \ No newline at end of file diff --git a/test/units/sprites/row_fitter_test.rb b/test/units/sprites/row_fitter_test.rb new file mode 100644 index 00000000..38096ef8 --- /dev/null +++ b/test/units/sprites/row_fitter_test.rb @@ -0,0 +1,66 @@ +require 'test_helper' +require 'compass/sass_extensions/sprites/row_fitter' + +class RowFitterTest < Test::Unit::TestCase + include SpriteHelper + def setup + file = StringIO.new("images_path = #{@images_src_path.inspect}\n") + Compass.add_configuration(file, "sprite_config") + end + + def row_fitter(images = nil) + @row_fitter ||= Compass::SassExtensions::Sprites::RowFitter.new(images) + end + + def teardown + @row_fitter = nil + end + + def create_images(dims) + dims.collect { |width, height| + image = Compass::SassExtensions::Sprites::Image.new('blah', 'blah', {}) + image.stubs(:width => width, :height => height) + image + } + end + + def basic_dims + [ + [ 100, 10 ], + [ 80, 10 ], + [ 50, 10 ], + [ 35, 10 ], + [ 20, 10 ] + ] + end + + it 'should use the fast placement algorithm' do + images = create_images(basic_dims) + + row_fitter(images) + assert_equal 100, row_fitter.width + + row_fitter.fit!(:fast) + + assert_equal 4, row_fitter.rows.length + + assert_equal [ images[0] ], row_fitter[0].images + assert_equal [ images[1] ], row_fitter[1].images + assert_equal [ images[2], images[3] ], row_fitter[2].images + assert_equal [ images[4] ], row_fitter[3].images + end + + it 'should use the scan placement algorithm' do + images = create_images(basic_dims) + + row_fitter(images) + + row_fitter.fit!(:scan) + + assert_equal 3, row_fitter.rows.length + + assert_equal [ images[0] ], row_fitter[0].images + assert_equal [ images[1], images[4] ], row_fitter[1].images + assert_equal [ images[2], images[3] ], row_fitter[2].images + end +end \ No newline at end of file