From 13397ccfe7df796ac44928e51ecba7ccfe7936e9 Mon Sep 17 00:00:00 2001 From: Stormwind Date: Fri, 1 May 2015 11:18:56 +0200 Subject: [PATCH] Add tests for Rubella::Storage.data, Rubella::Storage.new --- lib/rubella/storage.rb | 2 + spec/unit/rubella/storage/data_spec.rb | 11 +++++ spec/unit/rubella/storage/length_eql_spec.rb | 2 +- spec/unit/rubella/storage/new_spec.rb | 43 ++++++++++++++++++++ 4 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 spec/unit/rubella/storage/data_spec.rb create mode 100644 spec/unit/rubella/storage/new_spec.rb diff --git a/lib/rubella/storage.rb b/lib/rubella/storage.rb index 7a736b2..a92cd95 100644 --- a/lib/rubella/storage.rb +++ b/lib/rubella/storage.rb @@ -24,6 +24,8 @@ module Rubella # # Setting the length to 0 will disable this feature # + # TODO fill up with 0 values, if data is not multidemensional + # # @param length Integer The size of the storage # @return Integer The new size # diff --git a/spec/unit/rubella/storage/data_spec.rb b/spec/unit/rubella/storage/data_spec.rb new file mode 100644 index 0000000..2977912 --- /dev/null +++ b/spec/unit/rubella/storage/data_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Rubella::Storage, '.data' do + + it "retuns the stored data" do + storage = Rubella::Storage.new [3, 4, 5] + + expect(storage.data).to eq([3, 4, 5]) + end + +end \ No newline at end of file diff --git a/spec/unit/rubella/storage/length_eql_spec.rb b/spec/unit/rubella/storage/length_eql_spec.rb index 88586a4..ef5b552 100644 --- a/spec/unit/rubella/storage/length_eql_spec.rb +++ b/spec/unit/rubella/storage/length_eql_spec.rb @@ -65,4 +65,4 @@ describe Rubella::Storage, '.length=' do expect(storage.data.length).to eq(0) end -end \ No newline at end of file +end diff --git a/spec/unit/rubella/storage/new_spec.rb b/spec/unit/rubella/storage/new_spec.rb new file mode 100644 index 0000000..5f1920d --- /dev/null +++ b/spec/unit/rubella/storage/new_spec.rb @@ -0,0 +1,43 @@ +require 'spec_helper' + +describe Rubella::Storage, '.new' do + + it "creates a new Storage" do + storage = Rubella::Storage.new [] + + expect(storage).to be_an_instance_of(Rubella::Storage) + end + + it "fills the Storage with the given data" do + storage = Rubella::Storage.new [1, 2, 3] + + expect(storage.data).to eq([1, 2, 3]) + end + + it "disable length feature, if no length is given" do + storage = Rubella::Storage.new [1, 2, 3] + + expect(storage.length).to eq(3) + expect(storage.data.length).to eq(3) + end + + it "disable length feature, if length is 0" do + storage = Rubella::Storage.new [1, 2, 3], 0 + + expect(storage.length).to eq(3) + expect(storage.data.length).to eq(3) + end + + it "sets the length" do + storage = Rubella::Storage.new [1, 2, 3], 2 + + expect(storage.length).to eq(2) + end + + it "uses length feature, if length is given" do + storage = Rubella::Storage.new [1, 2, 3], 2 + + expect(storage.data.length).to eq(2) + end + +end \ No newline at end of file