Sha256: 06c2937177970f86114a6f3bfc08adfc15127dbf8639465cf4362262d59c1997

Contents?: true

Size: 699 Bytes

Versions: 3

Compression:

Stored size: 699 Bytes

Contents

require "spec_helper"
require "hamster/set"

describe Hamster::Set do
  describe "#first" do
    context "on an empty set" do
      it "returns nil" do
        S.empty.first.should be_nil
      end
    end

    context "on a non-empty set" do
      it "returns an arbitrary value from the set" do
        %w[A B C].include?(S["A", "B", "C"].first).should == true
      end
    end

    it "returns nil if only member of set is nil" do
      S[nil].first.should be(nil)
    end

    it "returns the first item yielded by #each" do
      10.times do
        set = S.new((rand(10)+1).times.collect { rand(10000 )})
        set.each { |item| break item }.should be(set.first)
      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/set/first_spec.rb
hamster-3.0.0 spec/lib/hamster/set/first_spec.rb
hamster-2.0.0 spec/lib/hamster/set/first_spec.rb