diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index ff04834..0783c3c 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -17,3 +17,4 @@ require 'rubella/weighting/exponential' require 'rubella/weighting/per_overall_load' require 'rubella/output/base' require 'rubella/output/ascii' +require 'rubella/output/image' diff --git a/spec/unit/rubella/output/image/new_spec.rb b/spec/unit/rubella/output/image/new_spec.rb new file mode 100644 index 0000000..588403f --- /dev/null +++ b/spec/unit/rubella/output/image/new_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper' + +describe Rubella::Output::Image, '.new' do + + it "creates a new Rubella::Output::Image" do + output = Rubella::Output::Image.new nil + + expect(output).to be_kind_of(Rubella::Output::Image) + end + + it "uses the given data" do + output = Rubella::Output::ImageImplementation.new Rubella::Storage.new([]) + + expect(output.data).to be_kind_of(Rubella::Storage) + expect(output.data.data).to eq([]) + end + + it "uses the given field_size" do + output = Rubella::Output::Image.new nil, 5 + + expect(output.field_size).to eq(5) + end + + it "uses 15 as default field_size" do + output = Rubella::Output::Image.new nil + + expect(output.field_size).to eq(15) + end + +end + +class Rubella::Output::ImageImplementation < Rubella::Output::Image + attr_reader :data +end diff --git a/spec/unit/rubella/output/image/render_spec.rb b/spec/unit/rubella/output/image/render_spec.rb new file mode 100644 index 0000000..054c995 --- /dev/null +++ b/spec/unit/rubella/output/image/render_spec.rb @@ -0,0 +1,38 @@ +require 'spec_helper' + +describe Rubella::Output::Image, '.render' do + + it "returns a Magick::Image" do + data = [ + [0, 0.1, 0.01], + [0, 0.3, 0.55], + [1, 0.64, 0.4] + ] + storage = Rubella::Storage.new(data) + output = Rubella::Output::Image.new storage + + expect(output.render).to be_kind_of(Magick::Image) + end + + it "creates an image from the given data" do + data = [ + [0, 0.1, 0.01], + [0, 0.3, 0.55], + [1, 0.64, 0.4] + ] + storage = Rubella::Storage.new(data) + output = Rubella::Output::Image.new storage, 2 + + image = [255, 253, 253, 255, 253, 253, 255, 115, 115, 255, 115, 115, 255, + 153, 153, 255, 153, 153, 255, 253, 253, 255, 253, 253, 255, 115, 115, 255, + 115, 115, 255, 153, 153, 255, 153, 153, 255, 229, 229, 255, 229, 229, 255, + 179, 179, 255, 179, 179, 255, 91, 91, 255, 91, 91, 255, 229, 229, 255, + 229, 229, 255, 179, 179, 255, 179, 179, 255, 91, 91, 255, 91, 91, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 1, 255, 1, + 1, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 1, 1, + 255, 1, 1].pack('C*') + + expect(output.render.export_pixels_to_str).to eq(image) + end + +end