Add test for Rubella::Output::Image
This commit is contained in:
parent
b345adb1d2
commit
14fbd23852
|
@ -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'
|
||||
|
|
|
@ -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
|
|
@ -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
|
Loading…
Reference in New Issue