Concatunate storages into new storage
Now we cat add new data to the old storage, which returns a new storage containg first the new data and then the old data. Plus a test for this, because it's not implemented now.
This commit is contained in:
parent
cf426e2a48
commit
808e8972b5
|
@ -25,6 +25,16 @@ module Rubella
|
|||
# TODO drop entries, if more than new length
|
||||
end
|
||||
|
||||
# Adds the data from the given storage to the own data and return this as a
|
||||
# new Storage. Does not modify one of the storages.
|
||||
#
|
||||
# @param storage Rubella::Storage Storage with new data
|
||||
# @return Rubella::Storage
|
||||
#
|
||||
def add storage
|
||||
Storage.new (storage.data+@data), @length
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -0,0 +1,9 @@
|
|||
if ENV['SIMPLECOV']
|
||||
require 'simplecov'
|
||||
SimpleCov.start do
|
||||
add_filter '_spec.rb'
|
||||
add_filter 'spec_helper.rb'
|
||||
end
|
||||
end
|
||||
|
||||
require 'rubella'
|
|
@ -0,0 +1,13 @@
|
|||
require 'spec_helper'
|
||||
|
||||
describe Rubella::Storage, '.add' do
|
||||
|
||||
it "returns a new Storage with the given Storages data before the old" do
|
||||
storage_1 = Rubella::Storage.new [3, 4, 5]
|
||||
storage_2 = Rubella::Storage.new [0, 1, 2]
|
||||
|
||||
storage_new = storage_1.add storage_2
|
||||
expect(storage_new.data).to eq([0, 1, 2, 3, 4, 5])
|
||||
end
|
||||
|
||||
end
|
Loading…
Reference in New Issue