Sha256: 5cdd23f62a4958d495cb10db5e3bc1a41e9e59d3174fb0082ed564e58f0adf5c

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

require "spec_helper"
require "hamster/vector"

describe Hamster::Vector do
  describe "#empty?" do
    [
      [[], true],
      [["A"], false],
      [%w[A B C], false],
    ].each do |values, expected|
      describe "on #{values.inspect}" do
        it "returns #{expected.inspect}" do
          V[*values].empty?.should == expected
        end
      end
    end
  end

  describe ".empty" do
    it "returns the canonical empty vector" do
      V.empty.size.should be(0)
      V.empty.object_id.should be(V.empty.object_id)
    end

    context "from a subclass" do
      it "returns an empty instance of the subclass" do
        subclass = Class.new(Hamster::Vector)
        subclass.empty.class.should be(subclass)
        subclass.empty.should be_empty
      end

      it "calls overridden #initialize when creating empty Hash" do
        subclass = Class.new(Hamster::Vector) do
          def initialize
            @variable = 'value'
          end
        end
        subclass.empty.instance_variable_get(:@variable).should == 'value'
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 2 rubygems

Version Path
files.com-1.0.55 docs/vendor/bundle/ruby/2.5.0/gems/hamster-3.0.0/spec/lib/hamster/vector/empty_spec.rb
hamster-3.0.0 spec/lib/hamster/vector/empty_spec.rb
hamster-2.0.0 spec/lib/hamster/vector/empty_spec.rb