Sha256: c1de1080e820ab58f8e40de2d9197f17631a0201adde36e7aeaccf1fa506bf6f

Contents?: true

Size: 1.2 KB

Versions: 2

Compression:

Stored size: 1.2 KB

Contents

require 'spec_helper'

require 'combinatorics/derange'

shared_examples_for "Derange::Mixin" do
  it "the derange of an empty Set should only contain an empty Array" do
    set     = subject[]
    results = set.derange.to_a
    
    results.should == [[]]
  end

  it "should return [[]] for [1].derange.to_a" do
    set     = subject[1]
    results = set.derange.to_a

    results.should == [[]]
  end

  it "should return [[2, 1]] for [1, 2].derange.to_a" do
    set     = subject[1, 2]
    results = set.derange.to_a

    results.should == [[2, 1]]
  end

  it "should return [[2, 1, 4, 3], [2, 3, 4, 1], [2, 4, 1, 3], [3, 1, 4, 2], [3, 4, 1, 2], [3, 4, 2, 1], [4, 1, 2, 3], [4, 3, 1, 2], [4, 3, 2, 1]] for [1, 2, 3, 4].derange.to_a" do
    set     = [1, 2, 3, 4]
    results = set.derange.to_a
    
    results.should == [
      [2, 1, 4, 3],
      [2, 3, 4, 1],
      [2, 4, 1, 3],
      [3, 1, 4, 2],
      [3, 4, 1, 2],
      [3, 4, 2, 1],
      [4, 1, 2, 3],
      [4, 3, 1, 2],
      [4, 3, 2, 1]
    ]
  end

  it "should take an optional block argument" do
    set     = subject[1, 2, 3]
    results = []

    set.derange { |deranged| results << deranged }

    results.should == [[2, 3, 1], [3, 1, 2]]
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
combinatorics-0.4.3 spec/derange/mixin_examples.rb
combinatorics-0.4.1 spec/derange/mixin_examples.rb