Sha256: 05e1ba1f61a11c41bc58e97dc5fbd5cc7c075943aae7fc4b79a0c5d7c92402d2

Contents?: true

Size: 1.75 KB

Versions: 3

Compression:

Stored size: 1.75 KB

Contents

require 'test/unit'

require 'methodic_hash'

class TC_MethodicHash < Test::Unit::TestCase
  
  def test_accesses
    
    mh = MethodicHash.new
    
    assert((mh['one'] = 1) == 1)
    assert(mh['one'] == 1)
    assert(mh[:one] == 1)
    assert(mh.one == 1)

    assert((mh[:two] = 2) == 2)
    assert(mh['two'] == 2)
    assert(mh[:two] == 2)
    assert(mh.two == 2)
    
    assert(mh['three'] == nil)
    assert(mh[:three] == nil)
    assert(mh.three == nil)
    
    assert((mh.four = 4) == 4)
    assert(mh['four'] == 4)
    assert(mh[:four] == 4)
    assert(mh.four == 4)
    
    assert(mh[1.25] == nil)
    
  end

  def test_remove
    
    mh = MethodicHash.new
    
    mh[:one] = 1
    assert(mh.size == 1)
    assert((mh.delete :one) == 1)
    assert(mh.size == 0)
    
    mh['two'] = 2
    assert(mh.size == 1)
    assert((mh.delete :two) == 2)
    assert(mh.size == 0)
    
    mh[:three] = 3
    assert(mh.size == 1)
    assert((mh.delete 'three') == 3)
    assert(mh.size == 0)
    
    mh['four'] = 4
    assert(mh.size == 1)
    assert((mh.delete 'four') == 4)
    assert(mh.size == 0)
    
    mh[:five] = 5
    mh['five'] = 'v'
    assert(mh.size == 2)
    deleted = mh.delete :five
    assert(deleted.index(5) != nil)
    assert(deleted.index('v') != nil)
    assert(mh.size == 0)
    
    mh[:six] = 6
    mh['six'] = 'vi'
    assert(mh.size == 2)
    deleted = mh.delete 'six'
    assert(deleted.index(6) != nil)
    assert(deleted.index('vi') != nil)
    assert(mh.size == 0)
    
    mh[:seven] = 7
    assert(mh.size == 1)
    assert((mh.delete 'eight') == nil)
    assert((mh.delete('nine') {|key| "#{key} not found"}) == "nine not found")
    assert(mh.size == 1)
    
  end

end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
eymiha_util-0.1.4 test/tc_methodic_hash.rb
eymiha_util-0.1.6 test/tc_methodic_hash.rb
eymiha_util-0.1.5 test/tc_methodic_hash.rb