Sha256: 75fe6ffa0ebca70f0718aa56d9750672393c5ab1fe3d9977ba778b145427bd49

Contents?: true

Size: 1.25 KB

Versions: 52

Compression:

Stored size: 1.25 KB

Contents

require File.expand_path('../../../../spec_helper', __FILE__)
require 'set'

describe "SortedSet#divide" do
  it "divides self into a set of subsets based on the blocks return values" do
    set = SortedSet["one", "two", "three", "four", "five"].divide { |x| x.length }
    set.map { |x| x.to_a }.to_a.sort.should == [["five", "four"], ["one", "two"], ["three"]]
  end

  it "yields each Object in self in sorted order" do
    ret = []
    SortedSet["one", "two", "three", "four", "five"].divide { |x| ret << x }
    ret.should == ["one", "two", "three", "four", "five"].sort
  end

  # BUG: Does not raise a LocalJumpError, but a NoMethodError
  #
  # it "raises a LocalJumpError when not passed a block" do
  #   lambda { SortedSet[1].divide }.should raise_error(LocalJumpError)
  # end
end

describe "SortedSet#divide when passed a block with an arity of 2" do
  it "divides self into a set of subsets based on the blocks return values" do
    set = SortedSet[1, 3, 4, 6, 9, 10, 11].divide { |x, y| (x - y).abs == 1 }
    set.map { |x| x.to_a }.to_a.sort.should == [[1], [3, 4], [6], [9, 10, 11]]
  end

  it "yields each two Objects to the block" do
    ret = []
    SortedSet[1, 2].divide { |x, y| ret << [x, y] }
    ret.should == [[1, 1], [1, 2], [2, 1], [2, 2]]
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/library/set/sortedset/divide_spec.rb