File: concat_spec.rb

package info (click to toggle)
ruby-immutable-ruby 0.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 1,852 kB
  • sloc: ruby: 16,556; makefile: 4
file content (34 lines) | stat: -rw-r--r-- 1,087 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
require 'spec_helper'

describe Immutable::Vector do
  [:+, :concat].each do |method|
    describe "##{method}" do
      let(:vector) { V.new(1..100) }

      it 'preserves the original' do
        vector.concat([1,2,3])
        vector.should eql(V.new(1..100))
      end

      it 'appends the elements in the other enumerable' do
        vector.concat([1,2,3]).should eql(V.new((1..100).to_a + [1,2,3]))
        vector.concat(1..1000).should eql(V.new((1..100).to_a + (1..1000).to_a))
        vector.concat(1..200).size.should == 300
        vector.concat(vector).should eql(V.new((1..100).to_a * 2))
        vector.concat(V.empty).should eql(vector)
        V.empty.concat(vector).should eql(vector)
      end

      [1, 31, 32, 33, 1023, 1024, 1025].each do |size|
        context "on a #{size}-item vector" do
          it 'works the same' do
            vector = V.new(1..size)
            result = vector.concat((size+1)..size+10)
            result.size.should == size + 10
            result.should eql(V.new(1..(size+10)))
          end
        end
      end
    end
  end
end