Sha256: 85b192a01269e5b792840bffc25fd97e54a02b9a059ecc579902088a34b5bf6a

Contents?: true

Size: 1.23 KB

Versions: 8

Compression:

Stored size: 1.23 KB

Contents

require 'spec_helper'
require 'bioinform/support/same_by'

describe Enumerable do
  describe '#same_by?' do
    it 'should be work with both hashes and arrays' do
      ['a','b','c'].same_by?{|k| k.length}
      {'a'=>13,'b'=>12,'c'=>14}.same_by?{|k,v| v < 20}
    end
    it 'should be true for empty collections' do
      [].same_by?(&:length).should be_true
      [].same_by?.should be_true
    end
    context 'without block' do
      it 'should compare if all elements of collection are the same' do
        %w{cat cat cat}.same_by?.should be_true
        %w{cat dog rat}.same_by?.should be_false
      end
    end
    context 'with a block' do
      it 'should compare enumerables by a value of block' do
        %w{cat dog rat}.same_by?(&:length).should be_true
        %w{cat dog rabbit}.same_by?(&:length).should be_false
      end
      it 'should be true if all elements are true' do
        [4,8,2,2].same_by?(&:even?).should be_true
      end
      it 'should be true if all elements are false' do
        [1,3,9,7].same_by?(&:even?).should be_true
      end
      it 'should be false if some elements are true and some are false' do
        [1,8,3,2].same_by?(&:even?).should be_false
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
bioinform-0.1.7 spec/support/same_by_spec.rb
bioinform-0.1.6 spec/support/same_by_spec.rb
bioinform-0.1.5 spec/support/same_by_spec.rb
bioinform-0.1.4 spec/support/same_by_spec.rb
bioinform-0.1.3 spec/support/same_by_spec.rb
bioinform-0.1.2 spec/support/same_by_spec.rb
bioinform-0.1.1 spec/support/same_by_spec.rb
bioinform-0.1.0 spec/support/same_by_spec.rb