Sha256: eff966b75ce35f4ce62e8e63af8fbbc55f63666b8f1e3664f6e0d941c7e9e3a6

Contents?: true

Size: 1.67 KB

Versions: 1

Compression:

Stored size: 1.67 KB

Contents

require 'spec_helper.rb'

describe Daru::Index do
  context "#initialize" do
    it "creates an Index from Array" do
      idx = Daru::Index.new ['speaker', 'mic', 'guitar', 'amp']

      expect(idx.to_a).to eq([:speaker, :mic, :guitar, :amp])
    end
  end

  context "#size" do
    it "correctly returns the size of the index" do
      idx = Daru::Index.new ['speaker', 'mic', 'guitar', 'amp']

      expect(idx.size).to eq(4)
    end
  end

  context "#re_index" do
    before :each do
      @old = Daru::Index.new [:bob, :fisher, :zakir]
    end
    it "returns a new index object" do
      n   = @old.re_index(@old + [:john, :shrinivas]) 

      expect(n.object_id).not_to eq(@old.object_id)
      expect(n.to_a).to eq([:bob, :fisher, :zakir, :john, :shrinivas])
    end

    it "does not over-ride existing indexes" do
      n = @old.re_index(@old + :bob)

      expect(n.object_id).not_to eq(@old.object_id)
      expect(n.to_a)     .to eq([:bob, :fisher, :zakir])
    end
  end

  context "#+" do
    before :each do
      @left = Daru::Index.new [:miles, :geddy, :eric]
      @right = Daru::Index.new [:bob, :jimi, :richie]
    end

    it "adds 2 indexes and returns an Index" do
      expect(@left + @right).to eq([:miles, :geddy, :eric, :bob, :jimi, :richie].to_index)
    end

    it "adds an Index and an Array to return an Index" do
      expect(@left + [:bob, :jimi, :richie]).to eq([:miles, :geddy, :eric, 
        :bob, :jimi, :richie].to_index)
    end
  end

  context "#[]" do
    it "works with ranges" do
      id = Daru::Index.new [:one, :two, :three, :four, :five, :six, :seven]

      expect(id[:two..:five]).to eq(Daru::Index.new([:two, :three, :four, :five]))
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
daru-0.0.4 spec/index_spec.rb