From 808e8972b5e6ca70cedcf3e723eaff4688370ec5 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Sat, 14 Mar 2015 10:29:15 +0100 Subject: [PATCH] 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. --- lib/rubella/storage.rb | 10 ++++++++++ spec/spec_helper.rb | 9 +++++++++ spec/unit/rubella/storage/add_spec.rb | 13 +++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 spec/spec_helper.rb create mode 100644 spec/unit/rubella/storage/add_spec.rb diff --git a/lib/rubella/storage.rb b/lib/rubella/storage.rb index 2c924ba..6c79d7f 100644 --- a/lib/rubella/storage.rb +++ b/lib/rubella/storage.rb @@ -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 diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb new file mode 100644 index 0000000..8783013 --- /dev/null +++ b/spec/spec_helper.rb @@ -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' diff --git a/spec/unit/rubella/storage/add_spec.rb b/spec/unit/rubella/storage/add_spec.rb new file mode 100644 index 0000000..2bb4e10 --- /dev/null +++ b/spec/unit/rubella/storage/add_spec.rb @@ -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