0
0
Fork 0

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:
Stormwind 2015-03-14 10:29:15 +01:00
parent cf426e2a48
commit 808e8972b5
3 changed files with 32 additions and 0 deletions

View File

@ -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

9
spec/spec_helper.rb Normal file
View File

@ -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'

View File

@ -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