Sha256: 7b92ce61316ac06c448f60daaaa78aeea6baf247d0c7501febbf3868e6d04081

Contents?: true

Size: 1.12 KB

Versions: 1

Compression:

Stored size: 1.12 KB

Contents

require 'spec_helper'
module Alf
  module Algebra
    module Operand
      describe Named, "hash and ==" do

        let(:op1){
          Named.new(:foo)
        }

        context '==' do

          it 'recognizes same operands' do
            op1.should eq(op1)
            op1.should eq(Named.new(:foo))
          end

          it 'distinguises other operands' do
            op1.should_not eq(nil)
            op1.should_not eq(Named.new(:foo, :bar))
          end
        end

        context 'hash' do

          it 'it the same on same operands' do
            op1.hash.should eq(Named.new(:foo).hash)
          end
        end

        context 'using named operands as hash keys' do

          let(:h){
            { op1 => 1,
              Named.new(:bar) => 2,
              Named.new(:foo, :bar) => 3 }
          }

          it 'should lead to expected hash' do
            h.size.should eq(3)
          end

          it 'should behave as expected' do
            h[op1].should eq(1)
            h[Named.new(:foo)].should eq(1)
            h[Named.new(:foo, :bar)].should eq(3)
          end
        end

      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
alf-core-0.15.0 spec/unit/alf-algebra/operand/named/test_hash_and_equal.rb