Sha256: 7b1b19d84a2b133248521b4532ab3f640dc4d71dc2426a14309b5abdf0497702

Contents?: true

Size: 871 Bytes

Versions: 1

Compression:

Stored size: 871 Bytes

Contents

require 'spec_helper'

describe Sperm::RandomPermutations do
  subject { Sperm::RandomPermutations.new(order) }

  describe '#rand' do
    context 'when order is zero' do
      let(:order) { 0 }
      it 'generates an empty permutation' do
        expect(subject.rand).to be_empty
      end
    end

    context 'when order is small' do
      let(:order) { 42 }
      it 'generates a permutation' do
        expect(subject.rand).to be_a_permutation
      end
    end

    context 'when order is large' do
      let(:order) { 10**8 }
      it 'generates at least first element of permutation' do
        expect(subject.rand.first).to be_between(0, order - 1)
      end
    end

    context 'when order is too large' do
      let(:order) { 10**100 }
      it 'raises an error' do
        expect { subject }.to raise_error Sperm::NoSuitableGroup
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
sperm-0.1.1 spec/sperm/random_permutations_spec.rb